107 - The Cat in the Hat
来源:互联网 发布:java launcher.dll 编辑:程序博客网 时间:2024/05/22 00:34
题目:107 - The Cat in the Hat
题目大意:就是有一只猫的帽子高度为H,表示它能够变出N个小伙伴帽子高度为(H/ (n + 1)),当帽子高度为1,则不能变出小伙伴为他干活,这样子的猫就得自己干活。
题目给你第一只猫的帽子高度,和要干活的猫的只数,求不用自己干活的猫的只数,和所有猫的帽子高度。
解题思路:从题目中得:(N+ 1)^ k == H; M = N ^ k; 先求出变出伙伴的次数k,然后其余的就是代公式。公式的话就是等比公式的求和。而这里涉及log,而log需要double型的精度,否则会有精度误差,并且最后的数要转换成整型的数就需要 + 0.5 四舍五入一下,因为int是下取整,如1.99本该取2的值,却取1的值。并且判断两个double的数相等,不能用= ,而是fabs(a - b)< 1e-10;
#include<stdio.h>#include<math.h>int h,m;int main() {while(scanf("%d %d", &h, &m) && h && m) {double n = 1;while(fabs(log(n)/log(n + 1) - log(m)/log(h))> 1e-10)n++;double k = log(h)/log(n + 1);if((int)(n + 0.5) == 1)printf("%d ", (int)(k + 0.5));elseprintf("%d ",int((1- pow(n, k))/(1 - n) + 0.5));printf("%d\n", int( (1 - pow(n/(n+1), k+1))*(n + 1) * h + 0.5 ));}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
- 107 - The Cat in the Hat
- UVA 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- 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
- 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
- Django:模型管理工具South
- zoj 3278 & scau_oj 10273 8G Island (二分)
- 在 CentOS 6.2 上安装 Puppet 配置管理工具
- Eclipse插件与平台快捷键冲突处理方法
- 成为高手
- 107 - The Cat in the Hat
- ThoughtWorks 实习记——重构与Intellij Idea初探
- Synchronized和ReentrantLock
- Eclipse Debug模式支持安装模型库
- zookeeper学习记录
- 三种权限设计方案的归纳和比较
- 在ubuntu12.04上部署openstack (3)
- How to resolve "your security settings have blocked an untrusted application from running" in Mac
- 三国佚事——巴蜀之危(全错排公式)