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 ...
随机推荐
- js模态窗口
最近在看js,正好公司用的框架中用到了模态窗口,以前没有接触过,现在把模态窗口的用法先记下来. 常用的浏览器chrome,Firefox,ie11,这三种分别支持document.open(),win ...
- Linux下通过rm -f删除大量文件时提示"-bash: /bin/rm: Argument list too long"的解决方法
Linux下通过rm -f删除/var/spool/postfix/maildrop/中大量的小文件时提示: "-bash: /bin/rm: Argument list too long& ...
- Clojure学习05:谓词函数
谓词函数是一个判断式,一个返回bool值的函数. clojure中(lisp习惯)有个规定:对于判断功能的函数,函数名后面都有一个“?”号.所以只要看到后面带问号的函数名,就知道这一定是一个判断函数. ...
- 模拟红外协议C程序——接收模块
目的:方便程序的调试,提供效率,减少工作累,可以不在线调试编程时显示实时数据,特别产品不带显示的或者MCU是OPT的,有很大的帮助. 过程:将要看的数据发送出来,另一个板(一个带有显示的就OK了,显示 ...
- Cocos2D-X扫盲之坐标系、锚点
一.引言 在Cocos2D-X的开发过程中,经常会碰到设置精灵位置的问题.而设置位置的过程,涉及到两个问题:第一是坐标系,包括原点的位置.X/Y坐标轴的方向灯:第二是基准点(Cocos2D-X中叫锚点 ...
- 13 - NSURLConnection
一.互联网 基本概念: HTTP协议 统一标准获取网络资源(其他设备上的东西) 本机 -> 远程服务器(计算机) URL(http有格式的字符串) 本机 <- 远程服务器(计算机) Fil ...
- 扩展 Windows Azure 运营能力 – 巴西
今天早些时候,在巴西圣保罗的一个活动上,我宣布了我们将在巴西设立一个 Windows Azure 区域数据中心的计划.我们希望该区域中心可以在 2014 年年初上线,并且我们很高兴地宣布将在未来 4 ...
- uva 10313 Pay the Price(完全背包)
题目连接:10313 - Pay the Price 题目大意:有0~300这300种价值的金额. 现在可能给出参数: 1个:n, 输出可以组成价值n的方式的个数. 2个:n, a输出用个数小于a的价 ...
- ※数据结构※→☆线性表结构(list)☆============单向循环链表结构(list circular single)(四)
循环链表是另一种形式的链式存贮结构.它的特点是表中最后一个结点的指针域指向头结点,整个链表形成一个环. 单循环链表——在单链表中,将终端结点的指针域NULL改为指向表头结点或开始结点即可. 循环链表的 ...
- 一步一步重写 CodeIgniter 框架 (4) —— load_class 管理多个对象实例的思路
我们使用CodeIgniter 框架最主要是想利用其 MVC 特性,将模型.视图分开,并通过控制器进行统一控制.在尝试实现 MVC 模式之前,我们将实现其中一个对程序结构非常有用的技巧,就是 load ...