POJ1289 UVA107 The Cat in the Hat【暴力】

The Cat in the Hat
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 1694 Accepted: 589

Description

(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!

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 1/(N+1)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).

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.

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

Source

Duke Internet Programming Contest 1991,UVA 107

问题链接POJ1289 UVA107 The Cat in the Hat
问题简述
????一只猫高为H, 去打扫一个房间,它很懒惰不想干活, 就从帽子里变出N只猫来帮它干活, 变出来的N只猫的高度为原来那只猫的1 / (N + 1);被变出来的N只猫也很懒惰不想干活,同样从帽子里变出N只猫(每1只变N只)帮自己干活,高度也变成原先的1 / (N + 1),......,直到猫的高度变为1(不具备再变小猫的能力,只能自己干活)为止, 计算有多少只猫不用干活,以及所有猫的高度总和。
问题分析
????假设变了k次:
????N^k=M,所以klog(N)=log(M),所以k=log(M)/log(N);
????H
(1/(N+1))^k=1,所以H=(N+1)^k,所以k=log(H)/log(N+1);
????N从1开始遍历,直到log(M)/log(N)-log(H)/log(N+1) 趋近于0为止。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* POJ1289 UVA107 The Cat in the Hat */

#include <bits/stdc++.h>

using namespace std;

const double ESP = 1e-10;

int main()
{
    int h, num;
    while(~scanf("%d%d", &h, &num) && (h || num)){
        double n = 1;
        while (fabs(log(n) / log(n + 1) - log(num) / log(h) )> ESP)
            n++;
        double k = int(log(h) / log(n + 1) + 0.5);
        if (int(n) == 1)
            printf("%d ", (int)k);
        else
            printf("%d ", int(0.5 + (1 - pow(n, k)) / (1 - n)));
        printf("%d\n", int(0.5 + (1 - pow(n / (n + 1), k + 1)) * (n + 1) * h));
    }

    return 0;
}

原文地址:https://www.cnblogs.com/tigerisland45/p/10404410.html

时间: 2024-11-06 18:47:17

POJ1289 UVA107 The Cat in the Hat【暴力】的相关文章

uva107 The Cat in the Hat

The Cat in the Hat Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 107 Appoint description: Description Download as PDF Background (An homage to Theodore Seuss Geisel) The Cat in the Hat is a nasty creature,

The Cat in the Hat UVA 107

说说:这道题开始还挺难理解的,一直搞不清到底要干嘛.其实,题意就是有一只猫,高度就是输入的init.它的帽子里有N只猫,每只猫的高度都是init的N+1分之一.然后这N只猫的帽子里同样有N只猫(其中中N为常数),大小类推....最后当猫的高度为1时,结束.输出高度不为1的猫的个数,并且输出这些猫的总高度.这里有几个特殊情况需要注意,就是第一只猫的帽子里就是高度为1的猫,另一种情况就是每个猫的帽子里都只有一只猫. 题目: The Cat in the Hat Background (An homa

UVa 107 - The Cat in the Hat

题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=43  The Cat in the Hat  Background (An homage to Theodore Seuss Geisel) The Cat in the Hat is a nasty creature,But the striped

UVA 107 The Cat in the Hat (数论)

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

杂题 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

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

查看redhat原有的yum包有哪些: [[email protected] ~]# rpm -qa|grep yum yum-utils-1.1.31-24.el7.noarch yum-langpacks-0.4.2-3.el7.noarch yum-metadata-parser-1.1.4-10.el7.x86_64 yum-rhn-plugin-2.0.1-4.el7.noarch PackageKit-yum-0.8.9-11.el7.x86_64 yum-3.4.3-118.el7

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

浙南联合训练赛20180214

这场比赛题目还行,但是被一道数学题卡了 A - Supermarket CodeForces - 919A We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that

HDU-1053-Entropy(Huffman编码)

Problem Description An entropy encoder is a data encoding method that achieves lossless data compression by encoding a message with "wasted" or "extra" information removed. In other words, entropy encoding removes information that was