poj3783 Balls
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 1110 | Accepted: 721 |
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?"
Suppose that we had only one ball. We'd have to drop from each floor from 1 to 100 in sequence, requiring 100 drops in the worst case.
Now consider the case where we have two balls. Suppose we drop the first ball from floor n. If it breaks we're in the case where we have one ball remaining and we need to drop from floors 1 to n-1 in sequence, yielding n drops in the worst case (the first ball is dropped once, the second at most n-1 times). However, if it does not break when dropped from floor n, we have reduced the problem to dropping from floors n+1 to 100. In either case we must keep in mind that we've already used one drop. So the minimum number of drops, in the worst case, is the minimum over all n.
You will write a program to determine the minimum number of drops required, in the worst case, given B balls and an M-story building.
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
Source
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int inf = 0x7ffffff;
int T;
int cas,n,m,f[][]; void solve()
{
memset(f,/,sizeof(f));
for (int i = ; i <= n; i++)
f[i][] = ;
for (int i = ; i <= m; i++)
f[][i] = i;
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
for (int k = ; k <= j; k++)
f[i][j] = min(f[i][j],max(f[i - ][k - ],f[i][j - k]) + );
} int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%d%d%d",&cas,&n,&m);
solve();
printf("%d %d\n",cas,f[n][m]);
} return ;
}
poj3783 Balls的更多相关文章
- [POJ3783]Balls 题解
题目大意 鹰蛋问题.$ n\(个蛋,\)m\(层楼. 存在一层楼\)E\(,使得\)E\(以及\)E\(以下的楼层鹰蛋都不会摔碎,问最坏情况下最少多少次能够知道\)E$. 非常经典的模型,初看题目根本 ...
- HDU5781 ATM Mechine(DP 期望)
应该是machine 和POJ3783 Balls类型相似. 现在上界为i元,猜错次数最多为j时,开始猜测为k元,有两种情况: 1 猜中:(i - k + 1) * dp[i - k][j] 2 猜不 ...
- 蓝桥杯-摔手机问题【dp】
非常详细的题解:戳这里 例题:poj-3783 Balls Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 115 ...
- Codeforces554 C Kyoya and Colored Balls
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...
- 13 Balls Problem
今天讨论的是称球问题. No.3 13 balls problem You are given 13 balls. The odd ball may be either heavier or ligh ...
- Open judge C16H:Magical Balls 快速幂+逆元
C16H:Magical Balls 总时间限制: 1000ms 内存限制: 262144kB 描述 Wenwen has a magical ball. When put on an infin ...
- hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...
- hdu 3635 Dragon Balls(并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- POJ 3687 Labeling Balls()
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9641 Accepted: 2636 Descri ...
随机推荐
- 001 -js对时间日期的排序
001-JS对时间日期的排序 最近在做公司的项目时间,产品给了一个很简单的页面,让帮忙写一下.首先看一下产品的需求: 需要对该列表进行排序 思路:(1)可以在数据库写sql语句的时间直接一个DESC按 ...
- PLSQL事务
1 使用set transaction设置事务属性 2 只读事务 set transaction read only 3 读写事务 set transaction write; 4 在进行数据统计分析 ...
- python—退出ipython3的help()
退出ipython3的help() 组合键:ctrl+z
- Linux java项目冲突不能正常运行
部署项目,在windows环境部署到Tomcat能够正常运行,部署到Linux环境下只能访问一些html资源,不能正常运行. 解决步骤: 1.清除webapps目录下所有文件夹,将war包上传至web ...
- 【算法设计与数据结构】为何程序员喜欢将INF设置为0x3f3f3f3f?(转)
摘自https://blog.csdn.net/jiange_zh/article/details/50198097 在算法竞赛中,我们常常需要用到一个“无穷大”的值,对于我来说,大多数时间我会根据具 ...
- pygame (1) 移动小乌龟
小乌龟图片素材: 第一个简单的小游戏: 小乌龟会不断的移动,并且每当到达窗口的左右边界的时候,还会自动的掉头. 源码: import pygame import sys# 导入sys模块,退出时使用 ...
- DataGridView,Dataset,DataTable,DataRow等使用心得
DataGridView的列编辑: Name:用于调用属性的时候用的,也可以不使用Name去调用,选择数字1,2,3...选择第1列,第2列,第3列. HeaderText:表头显示的名字方便用户使用 ...
- 03慕课网《vue.js2.5入门》——Vue-cli的安装,创建webpack模板项目
安装Vue-cli 第一种 貌似不可以,然后用了第二种,但是重装系统后,第二种不能用了,用了第一种可以 # 全局安装vue -cli命令npm install --global vue-cli # 创 ...
- 【树上DFS】Tree and Polynomials
http://codeforces.com/gym/101372 D push1[i][k]:所有操作1总共要让节点i下推多少系数k push2[i][k]:所有操作2总共要让节点i上推多少系数k s ...
- 团队Alpha冲刺(三)
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:丹丹 组员7:家伟 组员8:政演 组员9:鸿杰 组员10:刘一好 组员11:何宇恒 展示组内最 ...