UVA - 107 The Cat in the Hat
来源:互联网 发布:ubuntu terminal 分屏 编辑:程序博客网 时间:2024/05/17 22:21
UVA - 107 The Cat in the Hat
题目大意:给一只高H的猫 这只猫要打扫卫生 它会魔法 它可以变出N只 高 H/(N+1)的小猫(高为整数)帮它扫地 小猫也会魔法 也会变出 高H/(N+1)/(N+1)只小猫 当小猫高等与1 时 不能分了 只好取打扫 给定 第一只猫的高度H 和 最后要打扫的猫的个数 求 所有猫的总高和 要不打扫的猫的个数
解题思路: 列出等式解放串 可以得到 k(分裂次数) = logN(n) (N:分裂个数 n:扫地猫个数) H > (N+1)^k
所有得到 log(N)/log(N+1)-log(n)/log(H) > 0;
因为精度问题 所有 0要改成 1e-10
最后就是 个数的累加和 高度累加问题了
#include <cstdio>#include <cmath>using namespace std;int main() { int H,A; while ( scanf("%d%d", &H, &A), A || H) { int t = 1; while (abs(log(t)/log(t+1) - log(A)/log(H))>1e-10)t++; int k = log(H)/log(t+1) + 1e-10 + 0.5; long long int s = 0; long long int l = 1; long long int ss = 0; for (int i = 1; i <= k;i++) { ss+=H*l; s+=l; l*=t; H=H/(t+1); } ss+=l; printf("%lld %lld\n", s, ss); }}
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
- (OK) [android-x86-6.0-rc1] /system/etc/init.sh
- Scala类型参数中协变(+)、逆变(-)、类型上界(<:)和类型下界(>:)的使用
- 【浏览器渲染原理】 渲染树和页面渲染
- 2016互联网女皇报告中文版
- 在Node.js环境中使用OSS Javascript SDK来访问OSS服务
- UVA - 107 The Cat in the Hat
- jQuery笔记
- UVA - 573 The Snail
- UVA - 846 Steps
- 统一建模语言 UML淘宝网系统分析和设计
- UVA - 10499 the Land of Justice
- 系统架构师谈企业应用架构之开卷有益
- 应用缓存
- android 通知提醒