[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 ...
随机推荐
- python获取csv文本的某行或某列数据
#coding = 'utf-8' import csv # 使用list,只能读取列,而且是全文读取,csv.reader会自动把CSV内容生成数组 ''' df = csv.reader(open ...
- 用matplotlib对数据可视化
下图是要用到的数据集,反映了从1984到2016年的失业率的变化 1.导入可视化模块import matlibplot.pyplot as plt, 函数plt.plot(x, y)确定折线图的点,x ...
- 应用安全 - 无文件攻击 - Office漏洞 - 汇总
CVE-2017-0199 Date: -1 类型: 弹窗|内网穿透导致远程代码执行 影响范围: Microsoft Office 2007 Service Pack 3 Microsoft Offi ...
- spark 2.3.3 的MLlib 使用API
1.api官网 http://spark.apache.org/docs/2.3.3/ml-guide.html
- Python web 面试题(一)
1.列举django的内置组件? url .view.model.template.中间件 2.列举django中间件的5个方法?以及django中间件的应用场景? process_request(s ...
- vue组件化编程应用2
写几个小案例来理解vue的组件化编程思想,下面是一个demo. 效果图示: 需求: header部输入任务,进行添加,在list中显示; list中每个item项,鼠标移入时,背景变灰并显示delet ...
- P1219八皇后
这个题是一道USACO的经典dfs,与我见面的时间起码七个月了. 放置n个皇后于n*n棋盘,他们不能互相吃(行,列,对角线),问有几种摆法?于是想到了dfs(自我认为有图的就不用DP).首先确定好了要 ...
- Projection Pursuit Regression----读书笔记
The central idea is to extract linear combinations of the inputs as derived features, and then model ...
- 线性表源码分享(c++),包含顺序表、单链表、循环链表、双向链表
---恢复内容开始--- 我是一个c++和数据结构的初学者,本文主要是把清华大学出版社的数据结构(用面向对象方法与c++语言描述)(第2版)这本书中第二章线性表的源码抄下来,在学习的过程中有助于加深印 ...
- Tarjan水题系列(4):HAOI2010 软件安装
题目: 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi的和最大). ...