UVA 107 (暑假-数学 -E - The Cat in the Hat)
来源:互联网 发布:konect类似软件 编辑:程序博客网 时间:2024/05/21 15:38
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;All heights are positive integers.
these are the cats that get the work done.
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 1255764801 16796160 0
Sample Output
31 671335923 30275911#include <cstdio>#include <cmath>using namespace std;int main() {int height, number, k;while (scanf("%d%d", &height, &number) && (height || number)) {if (height == 1 && number == 1) {printf("0 1\n");continue;}//(N + 1) ^ K = height, N ^ K = number, (1 + number^(1 / K)) ^ K = number //帽子个数: N, 代数: K, 第一只猫的高度: height, 猫的数量: numberfor (k = 1; height != int(pow(1.0 + pow(number, 1.0 / k), k)+ 0.1); k++) ;int n = int(pow(number, 1.0 / k) + 0.1);int sum_number = 1, sum_height = height + number;for (int i = 1; i < k; i++) {sum_number += int(pow(n, i) + 0.1);sum_height += height / pow(n + 1, i) * int(pow(n, i) + 0.1) ;}printf("%d %d\n", sum_number, sum_height);}return 0;}
- UVA 107 (暑假-数学 -E - The Cat in the Hat)
- UVa 107 The Cat in the Hat (数学)
- uva 107 The Cat in the Hat(数学)
- uva 107 The Cat in the Hat
- uva 107 the cat in the hat
- uva 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- UVA 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- UVA 107 The Cat in the Hat
- uva 107 - The Cat in the Hat
- uva 107 The Cat in the Hat
- UVA 107 The Cat in the Hat
- uva 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- UVa - 107 - The Cat in the Hat
- UVa 107 - The Cat in the Hat
- UVA 107 The Cat in the Hat
- [android] Intent的setFlags
- [POJ 1204]Word Puzzles(Trie树暴搜&AC自动机)
- 林毅夫、张维迎先生之争让人失望
- halcon中通过字体确定图片的位姿的例子
- 简单易学的机器学习算法——Rosenblatt感知机的对偶解法
- UVA 107 (暑假-数学 -E - The Cat in the Hat)
- Android动画之弹球落地效果
- IRAT Iu Handover (UTRAN to EUTRAN)
- 寒城攻略:Listo 教你 25 天学会 Swift 语言 - 01 About Swift
- POJ3278 - Catch That Cow - 广度优先搜索
- 虚拟机网卡设置
- HDU 3081Marriage Match II(二分+并查集+网络流之最大流)
- Android中获取系统内存信息以及进程信息-----ActivityManager的使用
- 769 乘数密码