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

题意:给定两个数字,由1-100中得相乘,判断是否可以,可以大值赢。

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false);int f1, f2;void dfs(int a, int b, int k)
{if(b==1){f2 = 1;if(a==1) f1 = 1; // a和b都可以由相乘得到}if(k==1||(f1==1&&f2==1)) return; // a和b都可以由相乘得到或者数字到1即返回if(a%k==0) dfs(a/k,b,k-1); // a由该数相乘得到if(b%k==0) dfs(a,b/k,k-1); // b由该数相乘得到dfs(a,b,k-1); // ab都不由该数相乘
}int main()
{int n, m;while(cin>>n>>m){if(n==0&&m==0) break;if(n<m) swap(n,m); // 优先较大值f1 = 0; // 判断n能否得到f2 = 0; // 判断m能否得到dfs(n,m,100); if(f1==0&&f2==1){ // n不可以m可以输出mcout << m << endl; }else{ // 否则输出ncout << n << endl;}}return 0;
}

ZOJ:1003 Crashing Balloon(DFS)相关推荐

  1. 数据结构 笔记:图的遍历(DFS)

    深度优先(DFS) 深度优先算法 -原料:class LinkStack<T>; -步骤: -将起始顶点压入栈中 -弹出栈顶顶点v,判断是否已经标记(标记:转2,为标记:转3) -标记顶点 ...

  2. 绝地求生:大逃杀(dfs)

    Problem Description 绝地求生,是一款开放世界策略射击游戏,采用虚幻4引擎制作. 是一款大逃杀类型的游戏,每一局游戏将有100名玩家参与,他们将被投放在绝地岛(battlegroun ...

  3. 算法很美:水洼数(dfs)深搜

    题目描述 Descriptions: 由于近日阴雨连天,约翰的农场中中积水汇聚成一个个不同的池塘,农场可以用 N x M (1 <= N <= 100; 1 <= M <= 1 ...

  4. 题目1254:N皇后问题(DFS)

    题目描述: N皇后问题,即在N*N的方格棋盘内放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在同一斜线上.因为皇后可以直走,横走和斜走如下图). 你的任务是,对 ...

  5. 蓝桥杯:作物杂交 (DFS)

    目录 题目描述 输入描述 输出描述 输入输出样例 输入 输出 样例说明 思路(DFS): AC代码(Java): 题目链接 题目描述 作物杂交是作物栽培中重要的一步.已知有 N种作物 (编号 1 至  ...

  6. 算法学习笔记 4-3 深搜(DFS)与广搜(BFS):初识问题状态空间 与 LeetCode真题(Java)

    喜欢该类型文章可以给博主点个关注,博主会持续输出此类型的文章,知识点很全面,再加上LeetCode的真题练习,每一个LeetCode题解我都写了详细注释,比较适合新手入门数据结构与算法,后续也会更新进 ...

  7. 图文详解两种算法:深度优先遍历(DFS)和广度优先遍历(BFS)

    图文详解两种算法:深度优先遍历(DFS)和广度优先遍历(BFS) 阅读本文前,请确保你已经掌握了递归.栈和队列的基本知识,如想掌握搜索的代码实现,请确保你能够用代码实现栈和队列的基本操作. 深度优先遍 ...

  8. ES聚合算法原理深入解读:深度优先算法(DFS)和广度优先算法(BFS)(三)

    本文为:ES聚合算法原理深入解读:深度优先算法(DFS)和广度优先算法(BFS)第三篇 深度优先算法(DFS)和广度优先算法(BFS):DFS 和 BFS 在 ES 中的应用(一) 深度优先算法(DF ...

  9. ES聚合算法原理深入解读:深度优先算法(DFS)和广度优先算法(BFS)(一)

    本文为 ES聚合算法原理深入解读:深度优先算法(DFS)和广度优先算法(BFS)第一篇 深度优先算法(DFS)和广度优先算法(BFS):DFS 和 BFS 在 ES 中的应用(一) 深度优先算法(DF ...

  10. 三十二、图的创建深度优先遍历(DFS)广度优先遍历(BFS)

    一.图的基本介绍 为什么要有图 前面我们学了线性表和树 线性表局限于一个直接前驱和一个直接后继的关系 树也只能有一个直接前驱也就是父节点 当我们需要表示多对多的关系时, 这里我们就用到了图. 图的举例 ...

最新文章

  1. 并发异步处理队列 .NET 4.5+
  2. 一名提高选手的数论之路(一)
  3. 两款旋转编码器测量LDP3806,BH60
  4. H5Stream播放RTSP流视频
  5. boost::python::import相关的测试程序
  6. 计算机管理关机在哪,电脑点了关机为什么却关不了
  7. Debugging with GDB (6) gdb 命令
  8. DataFrame 排序
  9. Spring学习总结(29)——Spring异步处理@Async的使用以及原理、源码分析(@EnableAsync)
  10. 190707每日一句,一堂重要的人生之课Let it go, 穷则变变则通
  11. CPC客户端报错 error
  12. 标准串口定义-9转25的串口线接法图
  13. qq空间把android改成iphone,qq空间改iPhone6 Plus方法 qq空间改手机型号教程
  14. 用spss进行数据的标准化处理_SPSS统计分析案例:数据标准化
  15. 二清,是“担保支付”,还是“雁过拔毛”
  16. Linux下清除磁盘分区及残留raid信息
  17. linux设置软件的路径,linux下查看和设置软件的安装路径
  18. 位运算--异或运算XOR
  19. 百趣代谢组学文献分享:间歇性禁食调节糖尿病脑损伤多组学研究
  20. 安全刻不容缓「GitHub 热点速览 v.21.50」

热门文章

  1. SitePoint播客#26:力量在于您
  2. BFC(块级格式化上下文)
  3. 3w服务器把信息组织成,HTML小白入坑日记~qwq
  4. Autoleaders控制组——叶睿 第三次任务
  5. DAHnbsp;CEO:华尔街金融公司比区…
  6. 七日杀服务器直连教程,七日杀IP直连的方法
  7. Unity控制摄像机缓慢移动的代码(插值计算 非常丝滑)
  8. Android 渠道游戏 - 聚合SDK
  9. 基线、底线、顶线、中线
  10. SpringBoot优缺点分析