toj 3761 Egg Problem (好题~~)
Egg Problem
总提交: 22 测试通过: 7
描述
There is a very interesting problem described as follows:
You are given two eggs.
You have access to a 100-storey building.
An egg that survives a fall can be used again.
A broken egg must be discarded.
The effect of a fall is the same for all eggs.
If an egg breaks when dropped, then it would break if dropped from
a higher window.
If an egg survives a fall then it would survive a shorter
fall.
It is not ruled out that the first-floor windows break eggs, nor
is it ruled out that the 100th-floor windows do not cause an egg to break.
You need to figure out the highest floor an egg can be dropped
without breaking. The question is how many drops you need to make.
Now, I want to know how to solve this problem for any number of eggs and any
storeys. Can you help me?
输入
In the first line there is an integer T (T <= 10000), indicates the number
of test cases.
In each case, there are two integers n and m (1 <= n <= 15, 1 <= m
<= 100000), which are the number of eggs and storeys.
输出
For each case, the output format is “Case c: ans”.
c is the case number start from 1.
ans is the answer of this problem.
样例输入
2
2 100
3 100
样例输出
Case 1: 14
Case 2: 9
题目来源
原理:http://blog.sina.com.cn/s/blog_6c813dbd0101bh98.html
推导过程:http://blog.csdn.net/joylnwang/article/details/6769160
#include <stdio.h>
int dp[][];
void Init(){
for(int i=; i<=; i++){
for(int j=; j<=; j++){
if(i == ) dp[i][j] = j;
else if(i == j) dp[i][j] = (<<i)-;
else if(i >= j) dp[i][j] = dp[j][j];
else if(i < j) dp[i][j] = dp[i-][j-] + + dp[i][j-];
if(dp[i][j]>=){
break;
}
}
}
}
int main()
{
int T;
Init();
scanf("%d", &T);
for(int cas=; cas<=T; cas++){
int n, m;
scanf("%d %d", &n, &m);
for(int i=; ; i++){
if(dp[n][i] >= m){
printf("Case %d: %d\n", cas, i);
break;
}
}
}
return ;
}
toj 3761 Egg Problem (好题~~)的更多相关文章
- 2 Egg Problem
继续我们的推理问题之旅,今天我们要对付的是一个Google的面试题:Two Egg Problem. 我们开始吧! No.2 Google Interview Puzzle : 2 Egg Prob ...
- 【BZOJ1000】A+B Problem ★BZOJ1000题达成★
[BZOJ1000]A+B Problem Description 输入两个数字,输出它们之和 Input 一行两个数字A,B(0<=A,B<100) Output 输出这两个数字之和 S ...
- hdu-5867 Water problem(水题)
题目链接: Water problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Poj1207 The 3n + 1 problem(水题(数据)+陷阱)
一.Description Problems in Computer Science are often classified as belonging to a certain class of p ...
- Codeforces - 1194B - Yet Another Crosses Problem - 水题
https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...
- HDU 5475:An easy problem 这题也能用线段树做???
An easy problem Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDOJ(HDU) 2123 An easy problem(简单题...)
Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...
- codeforces 340C Tourist Problem(公式题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Tourist Problem Iahub is a big fan of tou ...
- HDU 5832 A water problem 水题
A water problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
随机推荐
- Treap基本用法总结
Treap=Tree+Heap 起名的人非常有才 Treap是啥? 一棵二叉搜索树可能退化成链,那样各种操作的效率都比较低 于是可爱的Treap在每个节点原先值v的基础上加了一个随机数rnd,树的形 ...
- CDH大数据平台搭建终极版
经过无数次的失败,终于将CDH安装到两台普通的笔记本电脑上,主要失败原因有以下几点: 不熟悉安装过程,官方给出的安装方法有三种,所以都尝试了一遍,浪费了大量时间,所以有时候方法多不见得是一件好事. 安 ...
- squeeze(s1,s2),将字符串s1中任何与字符串s2中匹配的字符都删除
void squeeze(char a[],char b[]) { //要实现把s2的任意字符如果出现的话就在s1中删除 //1.首先判断s1[j]==s2[i]&&s1[j]=='\ ...
- sqlserver2008:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。
在开始菜单中找到: 进入,点击左侧SQL Server服务, 将SQL Server(MSSQL.....)服务开启, 即可成功连接.
- MYGUI3.2改造——与HGE结合,实现资源打包
其实这个有点标题党的意思.MYGUI本身有资源打包的接口,可以实现从内存读取文件. 而HGE也提供了资源打包的功能(不过HGE的资源文件管理比较弱).把MYGUI的接口接到HGE上就可以实现MYGUI ...
- 团队项目-Beta冲刺1
博客介绍 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience 这个作业要求在哪里 https://w ...
- [HAOI2015]树上操作(树链剖分)
[HAOI2015]树上操作(luogu) Description 题目描述 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种: 操作 1 :把某个节点 x 的点权增 ...
- ios---CoreLocation框架实现定位功能
CoreLocation框架实现定位功能(iOS8.0之后) // // ViewController.m // 定位 // // Created by admin on 2017/9/20. // ...
- CTF--HTTP服务--SQL注入-X-Forwarded-For报文头
开门见山 1. 扫描靶场ip,发现PCS 192.168.31.196 2. 扫描靶场开放服务信息 3. 扫描靶场全部信息 4. 探测敏感信息 5. 查看靶场80端口的主界面 6. 使用AVWS工具进 ...
- Web 项目没有发布到我们安装的tomcat目录下
新手做Web项目的时候,在Ecplise把app发布到tomcat,但最后项目并没有发布到我们自己安装的 tomcat目录下,而是在.metadata\.plugins\org.eclipse.wst ...