[ZJU 1003] Crashing Balloon
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 each starts 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
Solution:
注意:先判断每个数是否合法,在进行搜索。搜索注意判重。
#include<bits/stdc++.h>
using namespace std;
int a,b;
int t[];
int check_DFS(int x,int lst)
{
if (x == )
return ;
int ret = ;
for (int i=lst;i<=;i++)
{
if (!t[i])
{
if (x % i == )
ret = check_DFS(x/i,i+);
if (ret == ) return ;
}
}
return ;
}
int check(int num)
{
return check_DFS(num,);
}
int DFS(int x,int lst)
{
for (int i=lst;i<= && i*i <= x;i++)
if (x % i == ) // Can divide
{
t[i] = ;
if (DFS(x/i,i+)) return ;
t[i] = ;
}
if (x <= )
{
if (t[x] == )
{
t[x] = ;
if (check(b)){
return ;
}
t[x] = ;
}
}
return ;
}
void solve()
{
memset(t,,sizeof(t));
if (a < b) swap(a,b);
int state_a = check(a);
int state_b = check(b);
if (state_a == && state_b == )
cout << a << endl;
else
if (state_b == )
cout << a << endl;
else
if (DFS(a,))
cout << a << endl;
else
cout << b << endl; }
int main()
{
while (cin >> a >> b)
solve();
}
[ZJU 1003] Crashing Balloon的更多相关文章
- [ZOJ 1003] Crashing Balloon (dfs搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题目大意:给你a,b两个数,问当b由约数1到100组成时,a能否由其 ...
- 1003 Crashing Balloon
考察DFS的应用,判断两个数的因子. #include <stdio.h> int f1,f2; void DFS(int m,int n,int k){ ){ f2=; ) f1=; } ...
- ZOJ 1003 Crashing Balloon
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- ZOJ1003 Crashing Balloon
Crashing Balloon Time Limit: 2 Seconds Memory Limit: 65536 KB On every June 1st, the Children's ...
- 【ZOJ1003】Crashing Balloon(DFS)
Crashing Balloon Time Limit: 2 Seconds Memory Limit: 65536 KB On every June 1st, the Children's ...
- 【Acm】算法之美—Crashing Balloon
题目概述:Crashing Balloon On every June 1st, the Children's Day, there will be a game named "crash ...
- ZJU-1003 Crashing Balloon dfs,
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题意(难以描述):A,B两个人从1~100选数乘起来比谁的大(不能选重复的或者 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
随机推荐
- input函数以及while处理列表和字典
一.函数input()的工作原理 .input()函数:获取输入的字符串 示例: message = input('请输入信息,方便电脑显示') print(message) print('您输入的信 ...
- angulart 常用
angular: 使用 echarts npm install echarts --save // 安装declare const echarts: any; // 引入https://www.ech ...
- jenkins shell 取当前时间
now=`date +%Y%m%d%H%M%S` echo $now newfilename=abc_${now}.warfor i in `ls *.jmx`:dojmeter -n -t $i r ...
- (4.24)【mysql、sql server】分布式全局唯一ID生成方案
参考:分布式全局唯一ID生成方案:https://blog.csdn.net/linzhiqiang0316/article/details/80425437 分表生成唯一ID方案 sql serve ...
- ubutu16.04编译安装apache
// 安装编译器 sudo apt-get install build-essential // 下载所需依赖及apache2源码包 wget --no-check-certificate https ...
- Windows node.js安装运行npm显示类似"ENOENT, stat 'C:\Users\XXXX\AppData\Roaming\npm'错误
这个错误是在玩一个小的博客的时候,使用到node.js,正好使用的是windows系统就安装了一个windows32的node.js版本 结果一运行npm就出现如上的错误,后来发现,只要在上面提到的目 ...
- 又是图论.jpg
BZOJ 2200 道路和航线重讲ww: FJ 正在一个新的销售区域对他的牛奶销售方案进行调查.他想把牛奶送到 T 个城镇 (1 ≤ T ≤ 25000),编号为 1 到 T.这些城镇之间通过 R 条 ...
- 哈希hash
定义 是把任意长度的输入(又叫做预映射pre-image)通过散列算法变换成固定长度的输出,该输出就是散列值 生成方法 hash() 哈希特性 不可逆 :在具备编码功能的同时,哈希算法也作为一种加密算 ...
- 2017第二届广东省强网杯线上赛--Nonstandard
测试文件:http://static2.ichunqiu.com/icq/resources/fileupload/CTF/echunqiu/qwb/Nonstandard_26195e1832795 ...
- 自动布局(storyboard,code)
xcode 6使用storyboard 进行自动布局,迷惑的问题主要由: 1,classsize 到底是一个什么东东? 2,classSize 和 layout 有什么区别? 3, 如何使用stor ...