UVA - 107 The Cat in the Hat
来源:互联网 发布:淘宝店设置低于7折 编辑:程序博客网 时间:2024/05/22 02:02
题目大意:一只猫可以叫N只猫,这些猫的高度是这只猫的1/N+1,这些猫又可以继续叫N只猫,直到这些猫的高度为1时才不能再叫,这些高度为1的猫就得去工作,最后求猫的总高度和不工作的猫的数量
解题思路:用数学公式推导,N的n次方等于不工作的猫的数量,(N+1)的n次方等于高度,又里两个公式可得N和n,既可以求结果
疑问:pow函数的精度问题搞不懂,如果后面没有加0.5,那么答案就是错的,为什么有的要加上0.5,而有的不用呢,真心搞不懂
#include<cstdio>#include<cmath>int main() {int height , worker;while(scanf("%d %d", &height, &worker) ) {if(worker == 0 && height == 0)break;if(worker == height && worker == 1) {printf("0 1\n");continue;}double n;int sum = height + worker;int notwork = 1;for(n = 1; ; n = n + 1 ) if(height == int(pow(1.0+pow(worker,1.0/n),n) + 0.5 ) )break;int N = int(pow(worker,1.0/n) + 0.5);for(int i = 1; i < n; i++) {sum = sum +pow(N*1.0,i) / pow(N+1.0,i) *height;notwork = notwork + pow(N*1.0,i);}printf("%d %d\n",notwork, sum);}return 0;}
0 0
- uva 107 The Cat in the Hat
- uva 107 the cat in the hat
- uva 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- UVA 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- UVA 107 The Cat in the Hat
- uva 107 - The Cat in the Hat
- uva 107 The Cat in the Hat
- UVA 107 The Cat in the Hat
- uva 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- UVa - 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- UVA 107 The Cat in the Hat
- Uva 107 The Cat in the Hat
- UVA - 107 The Cat in the Hat
- UVa 107 The Cat in the Hat
- Python宝典第19章:处理HTML与XML
- UI 常用方法总结之--- UILabel UITextField (不断更新中)
- 2014-10-06 让我们一起来对360误报说不!
- wpf 实现实时毛玻璃(live blur)效果
- C++标准库函数
- UVA - 107 The Cat in the Hat
- leetcode Permutation Sequence
- 使用glassfish在linux上的部署网站
- 在C + +实现
- Codeforces 475D CGCDSSQ 求序列中连续数字的GCD=K的对数
- IOS 启动画面和图标设置(适配IOS7 and Xcode5)
- [Codevs 1107][NOIP 1107]等价表达式
- php函数
- UI 常用方法总结之--- UIButton UIAlertView (不断更新中)