HIT OJ 1156 哈工大OJ
来源:互联网 发布:人工智能就是机器人吗 编辑:程序博客网 时间:2024/05/06 22:26
The Cat in the Hat
Submitted : 160, Accepted : 74
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题目意思很麻烦。。我在网上搜了一下题意:
一隻神奇聰明貓走進了一間亂七八糟的房間,他不想自己動手收拾,他決定要找幫手來工作。於是他從他的帽子中變出了N隻小貓來幫他(變出來的貓,高度為原來貓的 1/(N+1) )。這些小貓也有帽子,所以每一隻小貓又從他的帽子中變出N隻小小貓來幫他。如此一直下去,直到這些小小小....貓小到不能再小(高度=1),他們的帽子無法再變出更小的貓來幫忙,而這些最小的貓只得動手打掃房間。注意:所有貓的高度都是正整數。
在這個問題中,給你一開始那隻貓的高度,以及最後動手工作的貓的數目(也就是高度為1的貓的數目)。要請你求出有多少隻貓是沒有在工作的,以及所有貓的高度的總和。
#include<stdio.h>#include<math.h>#include<algorithm>#include<string.h>#define eps 1e-12using namespace std;double f(double h,double n){double temp;temp=pow(h,1.0/n)+eps;return pow(temp-1,n)+eps;}int main(){int k;double n,w,q,h;double left,right,mid;double ans1,ans2;while(scanf("%lf%lf",&h,&w)!=EOF){if(h==0&&w==0)break;left=0,right=62;for(k=1;k<=100;k++){mid=(left+right)/2;double temp=f(h,mid);if(temp>w)left=mid;elseright=mid;}n=mid;q=pow(h,1.0/n)+eps-1;ans1=(1-pow(q,n))/(1-q);ans2=h*(1-pow(q/(q+1),n+1))*(q+1);printf("%.0lf %.0lf\n",ans1,ans2);}return 0;}
- HIT OJ 1156 哈工大OJ
- HIT OJ 1069 哈工大
- HIT OJ 1076 哈工大OJ
- HIT OJ 1087 哈工大OJ
- hit oj 2255
- 【九度OJ】1490【字符串链接】【C实现】【哈工大2012】
- 【九度OJ】1489【矩阵乘法】【C实现】【哈工大2012】
- 【哈工大oj】1073 - 病毒(并查集,水)
- 【哈工大oj】1621 - 迷宫问题II(bfs,优先队列)
- HIT OJ 2060 Fibonacci Problem Again(矩阵快速幂)
- HIT OJ 2255 Not Fibonacci (矩阵快速幂)
- hit oj 1760 The jackpot (最大子段和)
- OJ
- OJ
- OJ
- OJ
- OJ
- OJ
- 利用sp_settriggerorder设置触发器执行顺序
- 使用字符串绑定TreeView
- 众人玩aiwi后的感受
- C# winform 捕获全局异常
- 【Ruby+Watir测试框架系列讲座 1】基础环境搭建
- HIT OJ 1156 哈工大OJ
- 分享memcache和memcached安装过程
- Solaris10 GCC bus error 一例
- CSS盒子模式之_相当定位和绝对定位
- 检测网络是否连接正常
- Linux console 乱码
- Strust 1.0 和 2.0 的区别
- 创业之路
- only 64-bit build environment are supported beyong froyo/2.2