[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 ...
随机推荐
- c#字符串代码,动态创建编译器
https://www.cnblogs.com/mrma/p/3998679.html 试了,确实可行,在unity也能用 值得注意的是UnityScript.Scripting.Evaluator ...
- Nginx代理自动上线下线
Nginx基于连接探测,如果发现后端异常,在单位周期为fail_timeout设置的时间,中达到max_fails次数,这个周期次数内,如果后端同一个节点不可用,那么接将把节点标记为不可用,并等待下一 ...
- 多线程14-Barrier
, b => Console.WriteLine()); ; i <= ; i++) { Console.Write ...
- [Web 前端] 030 ajax 是什么
AJAX 是什么 1. AJAX 是一种"艺术" 简单地说 AJAX 是在不重新加载整个页面的情况下与服务器交换数据并更新部分网页的艺术 网上是这样说的 AJAX 指异步 Java ...
- [转帖]kafka基础知识点总结
kafka基础知识点总结 https://blog.csdn.net/qq_25445087/article/details/80270790 需要学习. 1.kafka简介 kafka是由Apach ...
- ubuntu系统更新命令
一.图形界面更新升级 1.点击”系统设置“,打开“软件和更新”,切到“更新”栏目进行更新设置. 2.可以通过软件更新器进行更新升级自己想要更新的 二.命令方式更新升级 1.先解锁 ps -e|grep ...
- PHP7.2 、git、swoole安装
一.安装php 1.安装gcc yum -y install gcc gcc-c++ 2.安装一些库 yum -y install php-mcrypt libmcrypt-devel libxml2 ...
- GUI学习之三十三——QProgressBar学习总结
今天总结的是QProgressBar的使用方法 一.描述 提供了一个水平或垂直的进度条,用于向用户提供操作进度的指示,用户也可以从进度条看出来程序是否正在运行. 二.功能作用 1.设置范围和当前值 Q ...
- sshfs 挂载远程文件夹
1 安装 # yum install sshfs # dnf + releases] $ sudo apt-get install sshfs [On Debian/Ubuntu based syst ...
- java Byte源码分析
源码: public static int toUnsignedInt(byte x) { return ((int) x) & 0xff; } 原理: -128(byte) 原码:10000 ...