ZOJ_1003
2016-04-27 11:21
351 查看
ZOJ_1003: Crashing Balloon
Time Limit: 2000 MS Memory Limit: 64 MB64bit IO Format: %lld
[Submit][Status][Web
Board]
Description
On every June 1st, the Children's Day, there will be a game named "crashing balloon" on TV. The rule is very simple. On the ground there are 100 labeled balloons, with the numbers 1 to 100. After the referee shouts "Let's go!" the two players, who eachstarts with a score of "1", race to crash the balloons by their feet and, at the same time, multiply their scores by the numbers written on the balloons they crash. After a minute, the little audiences are allowed to take the remaining balloons away, and
each contestant reports his\her score, the product of the numbers on the balloons he\she's crashed. The unofficial winner is the player who announced the highest score.
Inevitably, though, disputes arise, and so the official winner is not determined until the disputes are resolved. The player who claims the lower score is entitled to challenge his\her opponent's score. The player with the lower score is presumed to have
told the truth, because if he\she were to lie about his\her score, he\she would surely come up with a bigger better lie. The challenge is upheld if the player with the higher score has a score that cannot be achieved with balloons not crashed by the challenging
player. So, if the challenge is successful, the player claiming the lower score wins.
So, for example, if one player claims 343 points and the other claims 49, then clearly the first player is lying; the only way to score 343 is by crashing balloons labeled 7 and 49, and the only way to score 49 is by crashing a balloon labeled 49. Since each
of two scores requires crashing the balloon labeled 49, the one claiming 343 points is presumed to be lying.
On the other hand, if one player claims 162 points and the other claims 81, it is possible for both to be telling the truth (e.g. one crashes balloons 2, 3 and 27, while the other crashes balloon 81), so the challenge would not be upheld.
By the way, if the challenger made a mistake on calculating his/her score, then the challenge would not be upheld. For example, if one player claims 10001 points and the other claims 10003, then clearly none of them are telling the truth. In this case, the
challenge would not be upheld.
Unfortunately, anyone who is willing to referee a game of crashing balloon is likely to get over-excited in the hot atmosphere that he\she could not reasonably be expected to perform the intricate calculations that refereeing requires. Hence the need for you,
sober programmer, to provide a software solution.
Input
Pairs of unequal, positive numbers, with each pair on a single line, that are claimed scores from a game of crashing balloon.
Output
Numbers, one to a line, that are the winning scores, assuming that the player with the lower score always challenges the outcome.
Sample Input
343 49 3599 610 62 36
Sample Output
49 610 62
Source
Zhejiang University Local Contest 2001看了题解以后自己写的。
思路要理清楚,这道题就是要求a,b有没有公共因子
假设a>b
从100到1每次枚举因数p,如果b可以整除p,那么就让b得到这个因子,b=b/p,进入递归,否则 如果a可以整除,就让a=a/p,进入递归
如果a==1了,那么a 合法,如果b==1了那么b合法。此处合法即为没有公共因子的条件下,ab被逐步分解完全。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
int t1,t2;
void solve(int a,int b,int p)
{
if(t1)
{
return ;
}
if(a==1)
{
t1=1;
return ;
}
if(b==1)
{
t2=1;
}
while(p)
{
if(b%p==0)
solve(a,b/p,p-1);
else if(a%p==0)
solve(a/p,b,p-1);
p--;
}
return ;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
t1=t2=0;
if(n<m)
swap(n,m);
solve(n,m,100);
if(!t1&&t2)
{
printf("%d\n",m);
}
else
{
printf("%d\n",n);
}
}
return 0;
}
相关文章推荐
- Android 视图组件的自定义
- 双击返回键退出应用
- iOS 最新AppStore审核指南
- C#设计模式--工厂方法
- 机器学习真的可以起作用吗?(2)(以二维PLA算法为例)
- 拿得起,放得下,想得开
- C# 在使用FindWindowEx的参数使用详解
- php面试题及答案
- JavaScript的回调问题
- 我要你快乐。。
- iOS开发]优化tableView性能(针对滑动时出现卡的现象)
- 剑指offer(36):第一个只出现一次的字符
- hdu1021 数学题 并不是说难,而是数学题那种简单朴素的思想get不到
- vim显示行号、语法高亮、自动缩进的设置
- 权重和层叠规则决定了CSS样式优先级
- Python函数式编程:内置函数reduce 使用说明
- [LeetCode]Flatten Binary Tree to Linked List
- header头解决跨域请求
- pycaffe
- 《疯狂Java讲义(第3版)》.(李刚)——数组