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 ...
随机推荐
- MacBook外接显示器设置方法(新手入门贴)
小屏幕的MacBook/MacBook Pro放在桌上长时间使用,眼睛比较累,而且,长时间低头看屏幕,易得颈椎病,绝对有损健康.配一台大屏幕的外置显示器不失为两全其美的好办法. 首先,得买一台中意的大 ...
- 百度SiteApp构建网站APP
现在很多个人网站和企业网站都是传统的Web方式,有没有想过个人/企业网站也能做成APP应用对外宣传呢?专门找人去开发Android和IOS上的APP又太贵,为了赶上移动互联网时髦,我以个人网站试做了一 ...
- Oracle统计之like,or关键字
有的时候我们统计需要like多个条件,比如某个字段中含有 “银行”或者“投资公司”,这个时候就用like多个字段. 如下是统计某个地区的2015年入院的病种诊断中带有 “癌”或者“肿瘤”的情况, 正确 ...
- 安装 unixbench 报错解决方法
一.准备工作 1.首先使用root用户登陆. 2.运行Unixbeanch需要GCC的支持,在安装Unixbeanch之前,需要先安装GCC,在Debian中,直接执行如下命令: 复制代码 代码如下: ...
- Python 2.7 学习笔记 列表的使用
同其它编程语言一样,python也提供了丰富的数据结构,以方便数据的处理.本文介绍两种最基本的数据集合,列表和元组的使用. 一.列表使用介绍 可以理解为一个有序的序列.其使用方式举例如下: list= ...
- QQ音乐产品经理黄楚雄:产品与用户的情感联系
QQ 音乐产品经理关于产品的一些感悟. 2014 年是 QQ 音乐的第十个产品年度,这十年我们跟用户一起见证了整个互联网音乐的发展.2011 年的 3 月 QQ 音乐公布了第一个 iPhone 平台的 ...
- nginx启动过程分析
nginx的启动过程紧紧环绕着ngx_cycle_t的结构体展开,首先通过ngx_get_options()获取命令行參数.然后通过ngx_time_init()进行时间的初始化.如全局变量ngx_c ...
- Objective-C KVC 自己主动转换类型研究
## Objective-C KVC 自己主动转换类型研究 apple非常厚道,kvc的时候帮我们做了一些类型转换,规律贴出来,给大伙參考參考 @interface Entity : NSObject ...
- BZOJ 4145: [AMPPZ2014]The Prices( 状压dp + 01背包 )
我自己只能想出O( n*3^m )的做法....肯定会T O( nm*2^m )做法: dp( x, s ) 表示考虑了前 x 个商店, 已买的东西的集合为s. 考虑转移 : 先假设我们到第x个商店去 ...
- java--方法和成员的继承,访问
//在调用方法的时候,不是看句柄是哪一个类,而应该看对象是属于哪一个类的,属于哪一个类的,就调用哪一个类的成员和方法. //子类可以添加自己的新方法,但是子类对象的引用赋值给父类句柄之后,不能使用父类 ...