| 800604 Hardness of eggs |
| Difficulty level: B; run time limit: 1000ms; operating space limit: 51200KB; code length limit: 2000000B |
| Question Description |
Recently XX Company held a strange competition: the King of the egg hardness tournament. Contestants are from all over the world hen, the content of the game is to see who lays the hardest, more strange is XX company does not use any precision instruments to measure the hardness of eggs, they used a most old-fashioned way-from the height of throwing eggs-to test the hardness of eggs, if the hen's eggs from the top of the high-level fell not broken But when I fell from the a+1 layer and broke it, it was said that the hen's egg hardness is a. You can certainly find a variety of reasons for this method unscientific, such as the same hen under the hardness of the egg may not be the same, but this does not affect the XX company's tournament, because they just to attract the attention of everyone, an egg from the 100-storey building fell off, the scene still can attract a lot of people stop to watch, Of course, XX Company will never forget to hang a piece on the high-rise, write "xx company" words-this competition is just XX company's an alternative advertisement. Thinking little a can always find a mathematical problem from one thing, and this is no exception. "If there are many eggs of the same hardness, then I can use a two-point method with the fewest number of times to determine the hardness of the eggs," small A to their own conclusion is very satisfied, but soon trouble, "but, if my eggs are not enough, for example, I have only 1 eggs, then I have to start from the 1th floor layer of , I'll throw it 100 times in the worst case. If you have 2 eggs, throw them away from the 2 floor. Wait, no, it's like you should start throwing it from 1/3, well, not necessarily. What about 3 eggs, 4, 5, more ... "and as always, little A is bogged down in an impasse of thought, rather than being diligent in thinking, rather than asking for trouble," he said. Well, since the trouble has come, someone has to solve, small a trouble depends on you to solve:) |
| Input |
The input includes multiple sets of data, one row per set of data, containing two positive integers n and M (1<=n<=100,1<=m<=10), where n represents the height of the building, and M represents the number of eggs you have now, The eggs are the same hardness (that is, they fall from the same height or are either broken or not broken), and are less than or equal to N. You can assume that an egg with a hardness of x from a height of less than or equal to X will not break in any case (the eggs that are not broken can continue to be used), and as long as they are thrown from a place higher than X, they will break. For each set of input data, you can assume that the egg's hardness is between 0 and N, that is, throwing an egg at the n+1 layer is bound to break. |
| Output |
| For each set of inputs, an integer is output that indicates the number of eggs to be thrown in the worst case scenario using the optimal strategy. |
| Input example |
100 1 100 2 |
| Output example |
100 14 |
| Other Notes |
Description: The optimal strategy is the worst-case scenario in which the least-throwing egg is required. If there is only one egg, you can only start from the first layer, in the worst case, the egg hardness is 100, so you need to throw 100 times. If you use other strategies, you may not be able to measure the hardness of an egg (such as when you first throw in the second floor, the result is broken, you can not determine whether the hardness is 0 or 1), that is, in the worst case you need to throw an unlimited number of times, so the first set of data answer is 100. |
|
Problem: 2004 thesis ... Nest Meng set G[i][j] said with J Egg Test I can determine the height. Proven time complexity O (sqrt (n)), Spatial complexity O (LOGN).
There is also a little bit of practice, set F[I][J] to indicate the height that can be determined with the I egg on the J-layer upstairs. Direct DP is O (n^3), plus the optimization of the Nether analysis is O (N^2LOGN), notice the monotonicity of the decision: F[i][j]>=f[i][j-1], Time complexity O (nlog^2n) ...
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn= -; One intn,eggnum,now=1, OLD,G[MAXN]; AInlineintRead () { - intx=0, sig=1;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; the for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0'; - returnsig?x:-x; - } -InlinevoidWriteintx) { + if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; + for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; A } at voidsolve () { - for(intI=2; i<=n;i++){ - for(intj=eggnum;j>=2; j--){ -g[j]=g[j-1]+g[j]+1; - if((J==eggnum) && (g[j]>=n)) {Write (i); ENT;return;} -}g[1]=i; in}return; - } to voidinit () { + intT; - while(SCANF ("%d", &n) = =1){ theeggnum=read (); * if(n<=1) {Write (1); ENT;Continue;} $ if(eggnum==1) {write (n); ENT;Continue;}Panax NotoginsengT=floor (log2 (n)) +1.0; - if(eggnum>=t) {write (t); ENT;Continue;} the for(intI=1; i<=eggnum;i++) g[i]=1; now=1; + solve (); A } the return; + } - voidWork () { $ return; $ } - voidprint () { - return; the } - intMain () {init (); work ();p rint ();return 0;}
Cojn 0585 800604 Egg hardness