标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 892 | Accepted: 588 |
Description
“Given two identical glass spheres, you would like to determine the lowest floor in a 100-story building from which they will break when dropped. Assume the spheres are undamaged when dropped below this point. What is the strategy that will minimize the worst-case scenario for number of drops?”
Input
Output
Sample Input
4 1 2 10 2 2 100 3 2 300 4 25 900
Sample Output
1 4 2 14 3 24 4 10题目大意: 有一些鸡蛋,我们现在想知道这些鸡蛋的硬度。然后现在有一座很高很高的大楼里,我们现在要在这座大楼上测试鸡蛋的硬度。每个鸡蛋的硬度相同,鸡蛋的硬度定义为:如果鸡蛋从第
/**
2016 - 08 - 03 上午
Author: ITAK
Motto:
今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e3+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
int dp[MAXN][60];///dp[i][j]:表示在 i 层楼 还有 j 个鸡蛋的最小判断次数
void Solve(int M, int N)
{
memset(dp, 0, sizeof(dp));///初始化
for(int i=1; i<=N; i++)///就一个鸡蛋,肯定是从第一层往上尝试的
dp[i][1] = i;
for(int i=1; i<=M; i++)///就一层,肯定是 1
dp[1][i] = 1;
for(int i=1; i<=N; i++)
{
for(int j=2; j<=M; j++)
{
dp[i][j] = INF;///初始化为比较大的值
for(int k=1; k<=i; k++)
dp[i][j] = min(dp[i][j],max(dp[k-1][j-1],dp[i-k][j])+1);
}
}
}
int main()
{
int op, N, M, T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&op,&M,&N);///N层 M个
Solve(M, N);
printf("%d %d\n",op, dp[N][M]);
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/qingshui23/article/details/52103660