Editorial for Thả trứng , trò giải trí tuổi teen


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

const fi='';
      fo='';
      maxn=1000;
      maxm=9;
var n,m,t,i:longint;
    f:array[1..maxm,1..maxn] of longint;
    pos:array[0..1,0..maxn] of longint;

procedure init;
var i,j,k,t,lt,z:longint;
begin
     for j:=1 to maxn do
     begin
          f[1,j]:=j; pos[1,j]:=j;
     end;
     pos[1,0]:=0;
     for i:=2 to maxm do
     begin
          z:=i and 1; t:=1; lt:=2; k:=1; f[i,1]:=1;
          pos[z]:=pos[1-z];
          while lt<=maxn do
          begin
               t:=t+pos[1-z,k]+1;
               if t>maxn then t:=maxn;
               for j:=lt to t do f[i,j]:=k+1;
               pos[z,k+1]:=t;
               lt:=t+1;
               inc(k);
          end;
     end;
end;

begin
     init;
     assign(input,fi); reset(input);
     assign(output,fo); rewrite(output);
     readln(t);
     for i:=1 to t do
     begin
          readln(m,n);
          if m>maxm then m:=maxm;
          writeln(f[m,n]);
     end;
     close(input); close(output);
end.

Code mẫu của ladpro98

#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <utility>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, a, b) for(int i = (a); i <=(b); ++i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define RESET(a, v) memset(a, (v), sizeof(a))
#define SZ(a) (int(a.size()))
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define LL long long
#define LD long double
#define II pair<int, int>
#define X first
#define Y second
#define VI vector<int>
#define VII vector<II>
#define endl '\n'

const int N = 1001;

using namespace std;

int dp[N][N], best[N][N];
int nTest;

void initialize() {
  //* dp[i][j] = i eggs, j floors
  FOR(i, 1, N) dp[1][i] = i;
  FOR(j, 1, N) {
    FOR(i, 2, N) {
      dp[i][j] = N;
      if (i > 3 && best[i - 1][j] == best[i - 2][j] && best[i - 2][j] == best[i - 3][j]) {
        int k = best[i][j] = best[i - 1][j];
        dp[i][j] = max(dp[i][j - k], dp[i - 1][k - 1]) + 1;
      } else {
        REP(k, 1, j) {
          int can = max(dp[i][j - k], dp[i - 1][k - 1]) + 1;
          if (dp[i][j] > can) {
            best[i][j] = k;
            dp[i][j] = can;
          }
        }
      }
    }
  }
}

void solve() {
  int x, y;
  while (nTest--) {
    cin >> x >> y;
    cout << dp[x][y] << endl;
  }
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  #ifdef _LAD_
    freopen("EGG.in", "r", stdin);
    freopen("EGG.out", "w", stdout);
  #endif // _LAD_
  cin >> nTest;
  initialize();
  solve();
  return 0;
}

Code mẫu của RR

{$R+,Q+}
program EGG;
const
  FINP='';
  FOUT='';
  MAXN=1001;
var
  m,n,test,t:longint;
  d:array[0..MAXN,0..MAXN] of longint;
  f1,f2:text;
procedure openF;
begin
  assign(f1,FINP); reset(f1);
  assign(f2,FOUT); rewrite(f2);
end;
procedure closeF;
begin
  close(f1); close(f2);
end;
procedure init;
var
  i,j:longint;
begin
  for i:=1 to MAXN do
    begin
      d[i,1]:=i;
      for j:=1 to MAXN do
        begin
          d[i,j]:=d[i-1,j]+d[i-1,j-1]+1;
          if d[i,j]>1000 then d[i,j]:=1500;
        end;
    end;
end;
procedure ans(m,n:longint);
var
  i:longint;
begin
  for i:=1 to MAXN do
    if d[i,n]>=m then
      begin
        writeln(f2,i);
        exit;
      end;
end;
begin
  openF;
  init;
  readln(f1,t);
  for test:=1 to t do
    begin
      readln(f1,n,m);
      ans(m,n);
    end;
  closeF;
end.

Code mẫu của hieult

#include <stdio.h>
    //#include <conio.h>
    int main()
    {
    int a[1000][1000],t,n,m,x;
    for(int i=0;i<1000;i++)
    {
    a[0][i]=1;
    a[i][0]=1;
    }
    for(int i=1;i<1000;i++)
    for(int j=1;j<1000;j++)
    a[i][j]=a[i][j-1]+a[i-1][j-1];
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
    scanf("%d %d",&n,&m);
    for(int j=0;j<1000;j++)
    {
    m=m-a[n-1][j];
    if(m<=0)
    {
    x=j;
    break;
    }
    }
    printf("%d\n",x+1);
    }
    //getch();
    }

Comments

Please read the guidelines before commenting.


There are no comments at the moment.