The Cat in the Hat
来源:互联网 发布:yc网络语言是什么意思 编辑:程序博客网 时间:2024/05/21 09:57
The Cat in the Hat
Background
(An homage to Theodore Seuss Geisel)
The Cat in the Hat is a nasty creature,
But the striped hat he is wearing has a rather nifty feature.
With one flick of his wrist he pops his top off.
Do you know what's inside that Cat's hat?
A bunch of small cats, each with its own striped hat.
Each little cat does the same as line three,
All except the littlest ones, who just say ``Why me?''
Because the littlest cats have to clean all the grime,
And they're tired of doing it time after time!
The Problem
A clever cat walks into a messy room which he needs to clean. Instead of doing the work alone, it decides to have its helper cats do the work. It keeps its (smaller) helper cats inside its hat. Each helper cat also has helper cats in its own hat, and so on. Eventually, the cats reach a smallest size. These smallest cats have no additional cats in their hats. These unfortunate smallest cats have to do the cleaning.
The number of cats inside each (non-smallest) cat's hat is a constant, N. The height of these cats-in-a-hat is times the height of the cat whose hat they are in.
The smallest cats are of height one;All heights are positive integers.
these are the cats that get the work done.
Given the height of the initial cat and the number of worker cats (of height one), find the number of cats that are not doing any work (cats of height greater than one) and also determine the sum of all the cats' heights (the height of a stack of all cats standing one on top of another).
The Input
The input consists of a sequence of cat-in-hat specifications. Each specification is a single line consisting of two positive integers, separated by white space. The first integer is the height of the initial cat, and the second integer is the number of worker cats.
A pair of 0's on a line indicates the end of input.
The Output
For each input line (cat-in-hat specification), print the number of cats that are not working, followed by a space, followed by the height of the stack of cats. There should be one output line for each input line other than the ``0 0'' that terminates input.
Sample Input
216 1255764801 16796160 0
Sample Output
31 671335923 30275911
已知原始猫高度H 与工作猫的个数M 设每次变N个猫 总共变了k次
那么 由题意得 N^k=M (N+1)^k=H
so k= log M/ log N = log H / log (N+1)
so log M / log H - log N / log (N+1)=0
那么 从N=1开始 试验使上式左侧无限趋近与0
#include<stdio.h>#include<math.h>const int maxn=2000;int main(){ int H,M,N,high,sum; while(scanf("%d%d",&H,&M)!=EOF&&H&&M) { N=1; while(fabs((log(M)/log(H))-(log(N)/log(N+1)))>0.00001) N++; sum=0; high=H; int n=1; while(H>1) { H/=(1+N); n*=N; sum+=n; high+=H*n; } sum-=M-1; printf("%d %d\n",sum,high); } return 0;}
- The Cat in the Hat
- The Cat in the Hat
- The Cat in the Hat
- The Cat in the Hat
- The Cat in the Hat
- The Cat in the Hat
- The Cat in the Hat
- poj1289 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
- 107 - The Cat in the Hat
- UVA 107 The Cat in the Hat
- uva 107 - The Cat in the Hat
- stl小知识点
- 删除jdk7之后用jdk6
- OpenGL ES 的 EGL API
- 什么是拉丁方设计?
- 好友拼图的原理
- The Cat in the Hat
- find按修改查找
- Cargo Daemon远程启动、停止服务器、部署项目
- CoCos2d-x 通过帧显示动画
- 计算机网络要点
- win7和手机共享文件和上网
- Sqlite第三方类库:FMDB使用
- iOS内存暴增问题追查与使用陷阱
- 山东理工大学ACM平台题答案关于C语言 1181 C语言实验——最小公倍数和最大公约数