杂题 UVAoj 107 The Cat in the Hat
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;
these are the cats that get the work done.
All heights are positive integers.
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 125
5764801 1679616
0 0
Sample Output
31 671
335923 30275911
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
int H,B;
while(~scanf("%d%d",&H,&B))
{
if(!(H|B))break; if(H==)
{
printf("%d %d\n",,);
continue;
}
int k;
for(k=;;k++)
if((int)(0.5+pow(pow(B*1.0,1.0/k)+1.0,k))>=H)
break;
int N=(int)(0.5+pow(B*1.0,1.0/k)),ans1=,ans2=;
for(int i=;i<k;i++)
{
ans1+=(int)(0.5+pow(N*1.0,i*1.0));
ans2+=((int)(0.5+pow(N*1.0,i*1.0))/pow(N+1.0,i)*H);
}
ans2+=B;
printf("%d %d\n",ans1,ans2);
}
return ;
}
杂题 UVAoj 107 The Cat in the Hat的更多相关文章
- UVa 107 - The Cat in the Hat (找规律,注意精度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- uva 107 - The Cat in the Hat
The Cat in the Hat Background (An homage to Theodore Seuss Geisel) The Cat in the Hat is a nasty c ...
- 杂题 UVAoj 10000 Longest Paths
Longest Paths It is a well known fact that some people do not have their social abilities complet ...
- 正睿OI DAY3 杂题选讲
正睿OI DAY3 杂题选讲 CodeChef MSTONES n个点,可以构造7条直线使得每个点都在直线上,找到一条直线使得上面的点最多 随机化算法,check到答案的概率为\(1/49\) \(n ...
- dp杂题(根据个人进度选更)
----19.7.30 今天又开了一个新专题,dp杂题,我依旧按照之前一样,这一个专题更在一起,根据个人进度选更题目; dp就是动态规划,本人认为,动态规划的核心就是dp状态的设立以及dp转移方程的推 ...
- wangkoala杂题总集(根据个人进度选更)
CQOI2014 数三角形 首先一看题,先容斥一波,求出网格内选三个点所有的情况,也就是C(n*m,3);然后抛出行里三点共线的方案数:C(n,3)*m; 同理就有列中三点共线的方案数:n*C(m,3 ...
- 2019暑期金华集训 Day6 杂题选讲
自闭集训 Day6 杂题选讲 CF round 469 E 发现一个数不可能取两次,因为1,1不如1,2. 发现不可能选一个数的正负,因为1,-1不如1,-2. hihoCoder挑战赛29 D 设\ ...
- Atcoder&CodeForces杂题11.7
Preface 又自己开了场CF/Atcoder杂题,比昨天的稍难,题目也更有趣了 昨晚炉石检验血统果然是非洲人... 希望这是给NOIP2018续点rp吧 A.CF1068C-Colored Roo ...
- Codeforces 杂题集 2.0
记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序 1326D2 - Prefix-Suffix Palindrome (Hard version) ...
随机推荐
- warning:This application is modifying the autolayout engine from a background thread
警告提示:This application is modifying the autolayout engine from a background thread, which can lead to ...
- 9.26 noip模拟试题
魔术球问题弱化版(ball.c/.cpp/.pas) 题目描述 假设有 n 根柱子,现要按下述规则在这 n 根柱子中依次放入编号为 1,2,3,…的球. (1)每次只能在某根柱子的最上面放球. (2) ...
- JAVA跑马灯实现1
<TextView android:layout_width="wrap_content" android:layout_height=" ...
- Java集群之session共享解决方案
随着互联网的日益壮大,网站的pv和uv成线性或者指数倍的增加.单服务器单数据库早已经不能满足实际需求.比如像盛大,淘宝这样的大型网络公司,更是如此. 集群,也就是让一组计算机服务器协同工作,达 ...
- transition的四个属性
transition-property 规定设置过渡效果的 CSS 属性的名称. transition-duration 规定完成过渡效果需要多少秒或毫秒. transition-timing-fun ...
- OSI七层模型理解
物理层功能1,为数据端设备提供传送数据的通路 功能2,传输数据 接口.传输介质.信号的传输.网络设备 有线介质:双绞线(普通的网线),光纤. 无线介质:无线电.微波.激光.红外线. 例如手机.电视接收 ...
- 如何在安卓/data(而不是/data/data)目录下进行文件的读写操作
分析:Android默认是无法直接操作/data目录的,只能读写程序自己的私有目录,也就是/data/data/package name/下,默认只能操作这个目录下的文件,也就是我们想直接读写/dat ...
- CI 笔记4 (easyui 手风琴)
添加父div标签,和子div标签 <div class="easyui-accordion" data-options="fit:true,border:false ...
- Android开发系列----学习伊始
因为对移动端开发开始感兴趣,开始学习App开发,没有苹果环境的我,只好先选择Android来玩一玩了~~ 找了一套视频,买了几本java.android开发的书,开始搞起~~
- mysql更新密码为空
1.进入命令行 mysql -u root -p 'oldpassword'; 2 修改root用户的密码:mysql> update mysql.user set password=PASSW ...