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. C# 内存管理优化畅想(一)---- 大对象堆(LOH)的压缩

    我们都知道,.net的GC是不会压缩大对象堆的,因为其时间开销不可接受,但这是以大对象堆产生大块碎片为代价的,如果以后要分配的大对象比最大的碎片还大,那么即使它比所有碎片的总大小要小,也是无法在不扩展 ...

  2. 表达式:使用API创建表达式树(6)

    一.ConstantExpression:表示具有常量值的表达式.因为表达式应用过程中,参数据多是 Expressions 类型,算是对常量值的一种包装吧. ConstantExpression使用比 ...

  3. HTML5 WebAudioAPI-实例(二)

    简单播放实例1: var url='../content/audio/海阔天空.mp3'; if (!window.AudioContext) { alert('您的浏览器不支持AudioContex ...

  4. java I/O的基本使用

    1.什么是I/O a.I/O也称为:输入输出,可以理解为In,Out b.I/O流:读取键盘键入的字符,硬盘上的文件 c.处理数据的类型分类:字节流.字符流 字节流:以Stream结尾的,可以处理图片 ...

  5. IIS 64位上發佈32位asp.net設置

    錯誤:無法載入檔案或組件 'Maticsoft.Web' 或其相依性的其中之一. 試圖載入格式錯誤的程式. 解決:新增應用程序池——高級設置——啟用32位應用程式——True

  6. hdoj 2049 错排

    代码: #include <stdio.h> int main(){ int n,a,b,i,j; __int64 s[22],h[22]; s[1]=0; s[2]=1; s[3]=2; ...

  7. POJ2584 T-Shirt Gumbo 二分图匹配(网络流)

    #include <cstdio> #include <cstring> #include <algorithm> const int inf=0x3f3f3f3f ...

  8. POJ 1830.开关问题(高斯消元)

    题目链接 Solutin: 将每个开关使用的情况当成未知数,如果开关i能影响到开关j,那么系数矩阵A[j][i]的系数为1. 每个开关增广矩阵的值是开关k的初状态异或开关k的目标状态,这个应该很容易想 ...

  9. gSoap实现ONVIF中xsd__anyType到具体结构类型的转换

    上一篇文章已经粗略计划要讨论gsoap关于序列化/解析编程. 本文则阐述一下关于gsoap生成代码的一些重要特征方法及使用.如题,下我们从ONVIF生成的C码中,挑选简单的一个类型来试验一下与xsd_ ...

  10. OC 字符和日期的互转

    需要用到NSDateFormatter这个类. 1.字符串转换为日期 [plain]NSDateFormatter* dateFormat = [[NSDateFormatter alloc] ini ...