UVa 10934 Dropping water balloons

探讨了使用有限数量的水球确定其从多高的楼层掉落会破裂的最少试验次数问题。通过数学建模找到最优解,避免过多体力劳动。

Problem A: Dropping water balloons

It's frosh week, and this year your friends have decided that they would initiate the new computer science students by dropping water balloons on them. They've filled up a large crate of identical water balloons, ready for the event. But as fate would have it, the balloons turned out to be rather tough, and can be dropped from a height of several stories without bursting!

So your friends have sought you out for help. They plan to drop the balloons from a tall building on campus, but would like to spend as little effort as possible hauling their balloons up the stairs, so they would like to know the lowest floor from which they can drop the balloons so that they do burst.

You know the building has n floors, and your friends have given you k identical balloons which you may use (and break) during your trials to find their answer. Since you are also lazy, you would like to determine the minimum number of trials you must conduct in order to determine with absolute certainty the lowest floor from which you can drop a balloon so that it bursts (or in the worst case, that the balloons will not burst even when dropped from the top floor). A trial consists of dropping a balloon from a certain floor. If a balloon fails to burst for a trial, you can fetch it and use it again for another trial.

The input consists of a number of test cases, one case per line. The data for one test case consists of two numbers k and n, 1≤k≤100 and a positive n that fits into a 64 bit integer (yes, it's a very tall building). The last case has k=0 and should not be processed.

For each case of the input, print one line of output giving the minimum number of trials needed to solve the problem. If more than 63 trials are needed then print More than 63 trials needed. instead of the number.

Sample input

 
2 100
10 786599
4 786599
60 1844674407370955161
63 9223372036854775807
0 0

Output for sample input

14
21
More than 63 trials needed.
61
63

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
// record[i][j]代表用i个气球尝试j次所能测出的楼层最高高度
long long record[110][65];

int main()
{
	// 算出所有答案
	record[0][0] = 0;
	record[1][0] = 0;
//	memset(record, 0, sizeof(record));
	for(int i = 1; i <= 100; i++)
	{
		for(int j = 1; j <= 63; j++)
		{
			record[i][j] = record[i-1][j-1] + 1 + record[i][j-1];	
		}
	}	

	long long k, n;
//	while(scanf("%lld %lld", &k, &n) == 2 && !(k == 0 && n == 0))
	while(cin >> k >> n && k)
	{
		int i;
		for(i = 1; i <= 63; i++)
		{
			if(record[k][i] >= n)
			{
				printf("%d\n", i);
				break;
			}	
		}	

		if(i > 63)
			printf("More than 63 trials needed.\n");
	}	
	return 0;	
}


该题目没有想出来,因为楼高太高,没法用数组来表示。
书上的做法是定义d(i,j)为用i个气球,尝试j次得到答案,所能测试的楼的最大高度。
假设一开始在第k层楼扔第一个气球,为了保证能在j次能得到答案。
如果气球破了,那么需要在1至(k-1)层用i-1个气球,尝试j-1得到答案。
k最大就为d(i-1,j-1)+1.
如果气球没破,那么在第k层楼之上的最大高度就为用i个气球,尝试j-1次得到答案
综上,最终的楼高应为d(i,j) = d(i-1,j-1) + 1 + d(i, j-1).

注意点是:当发现某个量不能表示进状态时(数值过大),考虑别的角度。
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值