UVA - 12119 The Bells are Ringing (枚举)
Perhaps you all have heard the mythical story about Tower of Hanoi (The details of this story is not required to solve this problem): “There is a tower of Hanoi with 64 disks and three pegs and the preists make one move everyday and the earth will be destroyed when all the pegs have been moved from one peg to the other following the rules of Tower of Hanoi.” In this problem we deal with a similar story – The story of an ancient temple. The ancient temple has three incredibly large bells. At the beginning of time the three bells rang together. Then the three bells never rang together and when they will ring together again the earth will be destroyed. The three bells have cycle length of t1, t2 and t3 (Here t1<t2<t3 and all are expressed in miliseconds). By this I mean that the first bell rings at every t1 seconds from the beginning, the second bell rings at every t2 second from the beginning and the third bell rings at every t3 second from the beginning. Also note that the difference of the values of t1, t2 and t3 is not that much different so that ordinary people think many time that they are ringing together.
Given the time difference between destruction of earth and beginning of time you will have to find the values of t1, t2 and t3.
Input
The input file contains at most 600 lines of inputs. Each line contains an integer which denotes (in millisecond) the time difference between the beginning of time and the time of the bells ringing together. Input is terminated by a line containing a single zero. All the input numbers will fit in a 64 bit signed integer.
Output
For each line of input produce two lines or more of output. The first line contains the serial of output. Each of the next lines contains three integers which denote the values of t1, t2 and t3 respectively. The value of t1, t2 and t3 is such that t1<t2<t3 and 0<t1, t2, t3≤1000000 and |t1-t3|≤25. If you cannot find values of t1, t2, t3 with such constraints then print the line “Such bells don’t exist” instead. In case there is more than one solution sort the output in ascending order of the value of t1, then (in case of a tie) in the ascending order of the value of t2 and then (still a tie) in ascending order of the value t3. Print a blank line after the output for each test case. Look at the output for sample input for details.
Sample Input Output for Sample Input
10 103 0 |
Scenario 1: 1 2 5 1 2 10 1 5 10 2 5 10
Scenario 2: Such bells don't exist
|
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = ; ll gcd(ll a, ll b) {
return b== ? a : gcd(b, a%b);
} int main() {
ll lcm;
int cas = ;
while (scanf("%lld", &lcm) != EOF && lcm) {
printf("Scenario %d:\n", cas++);
int flag = ;
for (ll i = ; i <= maxn && i <= lcm; i++) {
if (lcm % i)
continue;
for (ll j = i+; j-i <= ; j++) {
if (lcm % j)
continue;
ll tmp = (i * j) / gcd(i, j);
for (ll k = j+; k-i <= && k <= maxn; k++) {
if (lcm % k)
continue;
ll ans = (tmp * k) / gcd(tmp, k);
if (ans == lcm) {
printf("%lld %lld %lld\n", i, j, k);
flag = ;
}
}
}
}
if (!flag)
printf("Such bells don't exist\n");
printf("\n");
}
return ;
}
UVA - 12119 The Bells are Ringing (枚举)的更多相关文章
- UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...
- The Bells are Ringing(枚举)
Description Perhaps you all have heard the mythical story about Tower of Hanoi (The details of this ...
- The Bells are Ringing UVALive - 4060(枚举求解)
输出整数N,使得 t1 <= N 统计有多少组t1,t2,t3,满足:1<t1<t2<t3<=1000000,t3-t1<=25,且t1,t2,t3的最小公倍数 ...
- 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)
题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...
- UVA 11464 Even Parity(部分枚举 递推)
Even Parity We have a grid of size N x N. Each cell of the grid initially contains a zero(0) or a on ...
- uva 10245 The Closest Pair Problem_枚举
题意:求任意两点之间的距离的最少一个距离 思路:枚举一下就可以了 #include <iostream> #include<cstdio> #include<cmath& ...
- UVA 11464 Even Parity(递归枚举)
11464 - Even Parity Time limit: 3.000 seconds We have a grid of size N x N. Each cell of the grid in ...
- 【UVA】11464 Even Parity(枚举子集)
题目 传送门:QWQ 分析 标准的套路题. 枚举第一行,接着根据第一行递推下面的行. 时间复杂度$ O(2^n \times n^2) $ 代码 #include <bits/stdc++.h& ...
- uva 11752 The Super Powers (数论+枚举)
题意:找出1~2^64-1中 能写成至少两个数的幂形式的数,再按顺序输出 分析:只有幂是合数的数才是符合要求的.而幂不会超过64,预处理出64以内的合数. 因为最小的合数是4,所以枚举的上限是2的16 ...
随机推荐
- 百度SiteApp构建网站APP
现在很多个人网站和企业网站都是传统的Web方式,有没有想过个人/企业网站也能做成APP应用对外宣传呢?专门找人去开发Android和IOS上的APP又太贵,为了赶上移动互联网时髦,我以个人网站试做了一 ...
- iframe框架子页面与父页面间的通信
需要注意的问题:页面最好放在服务器上测试避免跨域问题. 具体参考:http://www.cnblogs.com/ljhero/archive/2011/07/09/2101540.html
- Python 第十二篇:HTML基础
一:基础知识: HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可 ...
- 我的Python成长之路---第三天---Python基础(9)---2016年1月16日(雾霾)
一.集合 set和dict类似,也是一组key的集合,但不存储value.由于key不能重复,所以,在set中,没有重复的key. 集合和我们数学中集合的概念是一样的,也有交集,并集,差集,对称差集等 ...
- [蘑菇街] 搜索、算法团队招募牛人啦-年底了走过路过不要错过 - V2EX
[蘑菇街] 搜索.算法团队招募牛人啦-年底了走过路过不要错过 - V2EX [蘑菇街] 搜索.算法团队招募牛人啦-年底了走过路过不要错过
- What’s New in Python 2.7 — Python 3.4.0b2 documentation
What's New in Python 2.7 - Python 3.4.0b2 documentation What's New in Python 2.7¶
- hdu2243之AC自动机+矩阵乘法
考研路茫茫——单词情结 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- android的fragments管理
FragmentManager 为了管理Activity中的fragments,需要使用FragmentManager. 为了得到它,需要调用Activity中的getFragmentManager( ...
- BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )
虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要 ...
- python变量传递给系统命令的方法
python程序内执行shell命令可以有几种方式,在http://www.cnblogs.com/xuxm2007/archive/2011/01/17/1937220.html 里都有详细介绍. ...