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的更多相关文章

  1. UVa 107 - The Cat in the Hat (找规律,注意精度)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  2. 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 ...

  3. 杂题 UVAoj 10000 Longest Paths

      Longest Paths  It is a well known fact that some people do not have their social abilities complet ...

  4. 正睿OI DAY3 杂题选讲

    正睿OI DAY3 杂题选讲 CodeChef MSTONES n个点,可以构造7条直线使得每个点都在直线上,找到一条直线使得上面的点最多 随机化算法,check到答案的概率为\(1/49\) \(n ...

  5. dp杂题(根据个人进度选更)

    ----19.7.30 今天又开了一个新专题,dp杂题,我依旧按照之前一样,这一个专题更在一起,根据个人进度选更题目; dp就是动态规划,本人认为,动态规划的核心就是dp状态的设立以及dp转移方程的推 ...

  6. wangkoala杂题总集(根据个人进度选更)

    CQOI2014 数三角形 首先一看题,先容斥一波,求出网格内选三个点所有的情况,也就是C(n*m,3);然后抛出行里三点共线的方案数:C(n,3)*m; 同理就有列中三点共线的方案数:n*C(m,3 ...

  7. 2019暑期金华集训 Day6 杂题选讲

    自闭集训 Day6 杂题选讲 CF round 469 E 发现一个数不可能取两次,因为1,1不如1,2. 发现不可能选一个数的正负,因为1,-1不如1,-2. hihoCoder挑战赛29 D 设\ ...

  8. Atcoder&CodeForces杂题11.7

    Preface 又自己开了场CF/Atcoder杂题,比昨天的稍难,题目也更有趣了 昨晚炉石检验血统果然是非洲人... 希望这是给NOIP2018续点rp吧 A.CF1068C-Colored Roo ...

  9. Codeforces 杂题集 2.0

      记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序   1326D2 - Prefix-Suffix Palindrome (Hard version) ...

随机推荐

  1. Linux chmod

    在Linux中要修改一个文件夹或文件的权限我们需要用到linux chmod命令来做. 语法如下: chmod [who] [+ | - | =] [mode] 文件名 命令中各选项的含义为 u 表示 ...

  2. 关于HTTP请求报文和响应报文学习笔记

    超文本传输协议(Hypertext Transfer Protocol,简称HTTP)是应用层的一种通信协议.它是一种请求/响应式的协议,即一个客户端与服务器建立连接后,向服务器发送一个请求;服务器接 ...

  3. (转)if语句优化

    一.使用常见的三元操作符  if (foo) bar(); else baz(); ==> foo?bar():baz(); if (!foo) bar(); else baz(); ==> ...

  4. dede 最近一天发布的文章标题前加hot

    {dede:list pagesize ='15'} <!-- 模板1 --> <div class="news_list tp_a setp1"> < ...

  5. struts_ognl详解

  6. <input value="hidden">的作用

    这样子上个页面的参数可以保存在这个页面,为下个页面获取参数做准备,在这个页面表单提交的时候下个页面可以获取参数

  7. 通过WebClient/HttpWebRequest实现http的post/get方法

    ///<summary>/// 通过WebClient类Post数据到远程地址,需要Basic认证: /// 调用端自己处理异常 ///</summary>///<par ...

  8. 禁用windows 10自动更新

    按Win键+R键调出运行,输入“gpedit.msc”点击“确定”,调出“本地组策略编辑器”.顺序依次展开计算机配置,管理模板 ,windows组件 ,windows更新 点击右边“配置自动更新”,选 ...

  9. php 备份和还原数据库

    ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去 $int ...

  10. iOS 视频播放横屏,隐藏状态栏

    MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] init]; ...