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

下面这些,不是我翻译的。。。可以借鉴

一只神奇聪明猫走进了一间乱七八糟的房间,他不想自己动手收拾,他決定要找帮手來工作。于是他从他的帽子中变出了N只小猫來帮他(变出來的猫,高度为原來猫的 1/(N+1) )。這些小猫也有帽子,所以每一只小猫又从他的帽子中变出N隻小小猫來帮他。如此一直下去,直到这些小小小....猫小到不能再小(高度=1),他们的帽子无法再变出更小的猫來帮忙,而这些最小的猫只得动手打扫房间。注意:所有猫的高度都是正整数。

在这个问题中,给你一开始那只猫的高度,以及最后动手工作的猫的数目(也就是高度为1的貓的数目)。要请你求出有多少只猫是沒有在工作的,以及所有猫的高度的总和。

hight number
   216        1
     36        5
       6      25
       1    125

N=5;

671=216*1+36*5+6*25+1*125

N^n=number

(N+1)^n=hight

lg(n)/lg(n+1)=lg(number)/lg(hgiht)

于是用二分查找算出N即可,条件就写成了fabs(lg(n)*lg(hgiht)-lg(number)*lg(n+1)< EPS)

参考http://blog.csdn.net/frankiller/article/details/7726744

 #include <cstdio>
#include <iostream>
#include <cmath>
using namespace std; #define EPS 1e-9 int main()
{
int hight, num;
int left, right, mid;
int x, y;
while(scanf("%d %d", &hight, &num) && (hight+num))
{
left = ;
right = ;
while(left)
{
mid = (left + right) / ;
///这就是在解方程,得到的mid就是 N
if(fabs( log(mid)*log(hight) - log(mid+)*log(num)) <= EPS) ///lg(n)/lg(n+1)可能等于0 ... N=1
break;
if(log(mid)*log(hight) - log(mid+)*log(num) > )
right = mid;
else
left = mid;
} ///x是计算,除去第一只猫,其余猫的数量,y是计算总高度
x = ;
y = hight;
left = ;
while(hight > )
{
hight /= (+mid);
left *= mid;
x += left;
y += hight*left;
}
printf("%d %d\n", x-num+, y);
} return ;
}

uva 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. 杂题 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 c ...

  3. The Cat in the Hat POJ - 1289

    题意:给你来两个数A,B  .其中A=(n+1)k, B=nk    输出:(nk-1)/(n-1) 和  ∏ (n+1)k-i ni 思路:关键就是怎么求n和k.本来想这n一定是几个质因数的乘积,那 ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. UVA题解一

    UVA 100 题目描述:经典3n+1问题在\(n \leq 10^6\)已经证明是可行的,现在记\(f[n]\)为从\(n\)开始需要多少步才能到\(1\),给出\(L, R\),问\(f[L], ...

  6. 更换Red Hat Enterprise Linux 7 64位的yum为centos的版本

    查看redhat原有的yum包有哪些: [root@localhost ~]# rpm -qa|grep yum yum-utils-1.1.31-24.el7.noarch yum-langpack ...

  7. 五、Pandas玩转数据

    Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...

  8. 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸

    类的继承案例解析,python相关知识延伸 作者:白宁超 2016年10月10日22:36:57 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给 ...

  9. python基础之正则表达式

    正则表达式语法 正则表达式 (或 RE) 指定一组字符串匹配它;在此模块中的功能让您检查一下,如果一个特定的字符串匹配给定的正则表达式 (或给定的正则表达式匹配特定的字符串,可归结为同一件事). 正则 ...

随机推荐

  1. Apache 的 httpd.conf 详解

    ServerRoot “/usr/local“ ServerRoot用于指定守护进程httpd的运行目录,httpd在启动之后将自动将进程的当前目录改变为这个目录,因此如果设置文件中指定的文件或目录是 ...

  2. Java bean validation 规范与参考实现

    1.Apache Bval 依赖包:validation-api-1.1.0.Final.jar org.apache.bval.bundle-1.1.1.jar bval-core-1.1.1.ja ...

  3. 安装CocoaPods报错 - [!] The dependency `AFNetworking (~> 3.1.0)` is not used in any concrete target.

    今天新机装cocopods时,等安装完毕发觉出现[!] The dependency `AFNetworking (~> 3.1.0)` is not used in any concrete ...

  4. Eclipse内存不够解决办法

    Window -- Preference --MyEclipse -- Servers -- Tomcat -- Tomcat6.x(选择自己安装的版本) -- JDK 在Optional Java ...

  5. sql server 常用的函数小汇

    摘录些许sqlserver 常用到的一些函数,便于日常学习使用 一.字符转换函数1.ASCII()返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字符串可不用‘’括起来,但 ...

  6. HTML5 – 1.基础

    新网页结构 1.<header> 定义了文档的头部区域 2.<nav>标签定义导航链接的部分. 3.<article>定义页面独立的内容区域. 4.<sect ...

  7. 设计模式学习之命令模式(Command,行为型模式)(12)

    一.命令模式的定义 命令模式属于对象的行为型模式.命令模式是把一个操作或者行为抽象为一个对象中,通过对命令的抽象化来使得发出命令的责任和执行命令的责任分隔开.命令模式的实现可以提供命令的撤销和恢复功能 ...

  8. 【网络资料】如何优雅地使用Sublime Text3

    如何优雅地使用Sublime Text3 Sublime Text:一款具有代码高亮.语法提示.自动完成且反应快速的编辑器软件,不仅具有华丽的界面,还支持插件扩展机制,用她来写代码,绝对是一种享受.相 ...

  9. ARM寻址方式,王明学learn

    ARM寻址方式 所谓寻址方式就是处理器根据指令中给出的信息来找到指令所需操作数的方式. 一.立即数寻址 立即数寻址,是一种特殊的寻址方式,操作数本身就在指令中给出,只要取出指令也就取到了操作数.这个操 ...

  10. Eclipse·如何关联Git库文件和添加JUint库

    Eclipse创建工程并关联到文件(SVN或Git管理的代码文件) 新建java工程,用于存放工程的一些信息,默认存放地址. 工程相关的信息是不需要提交到(SVN或Git)版本库的,所以工程存放到本地 ...