[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 ...
随机推荐
- jyputer notebook 、jypyter、IPython basics
1 .修改jupyter默认工作目录:打开cmd,在命令行下指定想要进的工作目录,即键入“cd d/ G:\0工作面试\学习记录”标红部分是想要进入的工作目录. 2.Tab补全 a.在命令行输入表达 ...
- python gevent(协程模块)
Python通过yield提供了对协程的基本支持,但是不完全.而第三方的gevent为Python提供了比较完善的协程支持. gevent是第三方库,通过greenlet实现协程,其基本思想是: 当一 ...
- 浅谈JVM及原理
前言 JVM一直是java知识里面进阶阶段的重要部分,如果希望在java领域研究的更深入,则JVM则是如论如何也避开不了的话题,本系列试图通过简洁易读的方式,讲解JVM必要的知识点. 运行流程 我们都 ...
- 重载Prometheus配置
发送SIGHUP信号给应用程序的主进程: pid ‘’-1‘’是指“终端断线” 发送post请求给指定端点: curl -XPOST http://ip:9090/-/reload 对于此种方法要注意 ...
- Java中字母大小写的转换
例:String str = "AbC"; 把字符串所有字母变成小写: System.out.println(str.toLowerCase()); 把字符串所有字母大写: Sys ...
- 第四周课程总结&第二次实验报告
实验二 Java简单类与对象 实验目的 掌握类的定义,熟悉属性.构造函数.方法的作用,掌握用类作为类型声明变量和方法返回值: 理解类和对象的区别,掌握构造函数的使用,熟悉通过对象名引用实例的方法和属性 ...
- Spring中的常见注解
@Controller 标识一个该类是Spring MVC controller处理器,用来创建处理http请求的对象. @RestController Spring4之后加入的注解,原来在@Co ...
- java8--- (Function、Predicate、Consumer) 通用函数式接口
// public static void main(String[] args) throws InterruptedException { // https://blog.csdn.net/u01 ...
- java http请求工具整理
处理了http 的get和post的请求,分别支持同步处理,异步处理两种方式下见代码. @Slf4jpublic class HttpUtils { /** * 同步请求http请求 不推荐 * * ...
- Redis---使用场景
3.使用场景 计数器 可以对String进行自增自减运算,从而实现计算器功能. Redis这种内存型数据库的读写性能非常高,很适合存储频繁读写的及数量 缓存 将热点数据放到内存中,设置内存 ...