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

题意:地面上有100个气球 编号为1~100 两个人踩气球 初始分数都是1 踩到相应编号的气球则分数乘以相应编号 最后两个人报出自己的分数 分数高的取胜 但是可能存在有人说谎的情况 分数低的人可以质疑分数高的人 如果分数高的人有一个分数不是自己踩气球得到的 则质疑是对的 分数低的选手是赢家 例如 分数高的选手要得到他说出的分数必须要踩到分数低的选手一定会踩到的气球 则质疑成功  另外 如果两个人分数都计算错误的话 则质疑被否决

题解:根据题目要求模拟 首先将分数高的赋值n 分数低的赋值m 之后通过递归因式分解 判断是否有公因子 因为气球编号是1~100 所以从100开始向下判断因子就好了 如果有公因子 分数低的选手是赢家 如果没有 分数高的选手是赢家 如果全部说谎或者全部正确 则判断高分获胜

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; bool aT, bT; void dfs(int n, int m, int p); int main(){
int n, m;
while(scanf("%d%d", &n, &m) != EOF){
if(n < m){ //将分数高的赋值n 分数低的赋值m
swap(n, m);
} aT = false; //先将a b都赋值为说谎
bT = false; dfs(n, m, ); //递归因式分解 if(!aT && bT){ //只有高分的说谎 则输出低分
printf("%d\n", m);
}
else{ //高分的没有说谎或者全部说谎或者全部正确 则输出高分
printf("%d\n", n);
}
}
return ;
} void dfs(int n, int m, int p){
if(n == && m == ){ //两个人都没有说谎 将aT赋值为没有说谎就好了
aT = true;
return ;
}
if(m == ){ //低分者没有说谎
bT = true;
} while(p > ){ //因式分解
if(n % p == ){
dfs(n/p, m, p-);
}
if(m % p == ){
dfs(n, m/p, p-);
} --p;
}
}

Alpha

【ZOJ1003】Crashing Balloon(DFS)的更多相关文章

  1. 【算法】深度优先搜索(dfs)

    突然发现机房里有很多人不会暴搜(dfs),所以写一篇他们能听得懂的博客(大概?) PS:万能 yuechi ---- 大法师怎么能不会呢?! 若有错误,请 dalao 指出. 前置 我知道即使很多人都 ...

  2. 【搜索】棋盘问题(DFS)

    Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...

  3. 【算法】深度优先搜索(DFS)III

    1. DFS生成排列 众所周知,1,2…n的排列一共有n!个,因此生成全排列至少需要n!的时间复杂度.如果用循环来生成排列,当n稍大时,内外循环会非常之多.可以用DFS模拟解决,生成0 … n-1的排 ...

  4. 【UVa】208 Firetruck(dfs)

    题目 题目     分析 一开始不信lrj的话,没判联通,果然T了. 没必要全部跑一遍判,只需要判断一下有没有点与n联通,邻接表不太好判,但无向图可以转换成去判n与什么联通. 关于为什么要判,还是因为 ...

  5. 【HDOJ6628】permutation 1(dfs)

    题意:求1到n的排列中使得其差分序列的字典序为第k大的原排列 n<=20,k<=1e4 思路:爆搜差分序列,dfs时候用上界和下界剪枝 #include<bits/stdc++.h& ...

  6. 【Luogu】P3761城市(dfs)

    题目链接 emmm我思维好水…… 想了一会lct发现好像不对,然后开始转DP稍微有一点思路,然后看了题解…… 首先可以枚举边,然后原树被你拆成了两个子树. 设D1D2是两个子树的直径,W1W2是子树内 ...

  7. CJOJ 1071 【Uva】硬币问题(动态规划)

    CJOJ 1071 [Uva]硬币问题(动态规划) Description 有n种硬币,面值分别为v1, v2, ..., vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为 ...

  8. 【Luogu1273】有线电视网(动态规划)

    [Luogu1273]有线电视网(动态规划) 题面 题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端, ...

  9. 【Luogu2458】保安站岗(动态规划)

    [Luogu2458]保安站岗(动态规划) 题面 题目描述 五一来临,某地下超市为了便于疏通和指挥密集的人员和车辆,以免造成超市内的混乱和拥挤,准备临时从外单位调用部分保安来维持交通秩序. 已知整个地 ...

随机推荐

  1. CSS布局学习笔记之position

    CSS知识点 之 position布局 前段时间被同学怂恿,参加了百度前端技术学院的一个小培训,第一个阶段下来学到不少东西.课程的第一个阶段主要是HTML5 和 CSS 基础知识的一个小培训,给出的一 ...

  2. 存到cookie里能提高性能吗?

    今天刚刚看了篇微信,大体意思是说g哥之类的网站把很多存session的东西都放cookie里了,可减少服务器的负担种种.然后我就发现我对request到application的记忆有些模糊了,哪些是在 ...

  3. iOS架构师之路:慎用继承

    最近在看大神Casa的文章<跳出面向对象思想(一) 继承>,脑洞大开.文章给我们展示了一个随着产品需求不断变化的例子,该例子中通过继承实现不同页面的搜索视图和搜索逻辑的代码复用,随着产品需 ...

  4. web前端教程之javascript创建对象的方法

    今天给大家讲讲javascript基础教程中的javascript面向对象的技术,这一次我们深入的学习一下JavaScrip基于t面向对象之创建对象,关于面向对象的一些术语这里就不给大家介绍了,不了解 ...

  5. oracle数据类型

    本文转自:http://blog.csdn.net/defonds/article/details/4302695 谢谢原文作者 有道是,磨刀不误砍柴工.多了解一些底层的东西,对于Oracle开发.维 ...

  6. 预装win8的系统换win7需要做的bios设置

    https://zhidao.baidu.com/question/873669708066476212.html (一)联想G50-70由于预装的是WIN8位系统,哪么改装WIN7 64位的方法如下 ...

  7. Windows 10和Visual Studio 2015 能给.Net方向的开发从业者带来什么?

    .Net 多年前我们选择了你,现在在当前的移动互联网热火朝天的时代,你能给我们什么样的惊喜?面对IOS和android的势头,windows的移动端能否实现三国鼎立? windows 10 号称统一各 ...

  8. LaTex表格内单元格内容强制换行

    /newcommand{/tabincell}[2]{/begin{tabular}{@{}#1@{}}#2/end{tabular}}%放在导言区 %然后使用&/tabincell{c}{} ...

  9. 29 个你必须知道的 Linux 命令

    虽然Linux发行版支持各种各样的饿GUI(graphical user interfaces),但在某些情况下,Linux的命令行接口(bash)仍然是简单快速的.Bash和 Linux Shell ...

  10. [转帖]网络协议封封封之Panabit配置文档

    原帖地址:http://myhat.blog.51cto.com/391263/322378