原题描述:

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

题意还是很好理解的,就是比较这两个人的分数判断谁输谁赢。

大致分析有三种情况 ( 已知A>B )

1. A , B 分数都正常,那么A赢。

2. A B 分数不正常 , B 撒谎 , A 赢。

3. A B 分数不正常, B 没撒谎, B 赢。

正常是指,这两个数可以因式分解为两个不同的因子,即找到其中的A1 , A2 , B1 , B2 使得 A = A1*A2 , B = B1*B2 成立,同时这四个数在1-100之间而且互不相等(因为每个气球数都是唯一的) 比如62=2*31 ,36 = 3*12 ,就属于第一种情况。

那么不正常是指一旦有某个因子大于100 那么这个结果本身就不正确了属于计算错误。如3599 = 1*3599 ,显然不可能有3599这个气球,所以A 撒谎。属于第三种情况。

又或者这四个因子其中有相等的数,如343 和49 , 343 = 7*49 ,而49 = 1*49 (不可能是7*7 ,因为7只能出现一次) ,因子49同时出现两次,那么判断A撒谎, B 赢 。也是第三种情况。

代码里有点混乱的地方就是判断因子的时候,太紊乱了。借鉴了网上的代码、

#include <stdio.h>
int flag1 , flag2 ;
void dfs( int a , int b , int k )
{int kk = k ;if ( a == 1 && b == 1 )  /* a和b都分解到了最后 */{flag1 = 1 ;                  /* a没撒谎 */return ;}if ( b == 1 )flag2 = 1 ;                  /* b没撒谎 */while ( ( a > kk || b > kk ) && k < 100 ){                                    /* 找到ab所有各不相同的因子,再从这些因子中搜索,看是否能重新乘出ab */kk ++ ;if ( a % kk == 0 ){dfs( a/kk , b , k );if ( flag1 )return ;}if ( b % kk == 0 ){dfs( a , b/kk , k );if ( flag1 )return ;}}
}
int main ( )
{int num1 , num2 , temp ;while ( ( scanf("%d %d",&num1 , &num2 ) ) != EOF ){flag1 = 0 , flag2 = 0 ;        /* 假设都说的假话 */if ( num1 < num2 ){temp = num1 ;num1 = num2 ;num2 = temp ;}else if ( num1 > num2 ){dfs ( num1 , num2 , 1 );if ( flag1 == 0 && flag2 == 1 )printf("%d\n",num2 );elseprintf("%d\n",num1 );}}return 0;
}

1003.Crashing Balloon相关推荐

  1. ZOJ1003 Crashing Balloon【水题】

    Crashing Balloon Time Limit: 2 Seconds Memory Limit: 65536 KB On every June 1st, the Children's Day, ...

  2. 【算法】算法之美—Crashing Balloon

    题目概述:Crashing Balloon On every  June 1st, the Children's Day, there will be a game named "crash ...

  3. 【Acm】算法之美—Crashing Balloon

    题目概述:Crashing Balloon On every  June 1st, the Children's Day, there will be a game named "crash ...

  4. ZJU1003 Crashing Balloon - 踩气球

    题目大意: 输入两个正整数x,y,判断x和y能否由1到100之间的整数乘积组成,数字不能重复使用. 分析: 想不到很好的方法,一般考虑用搜索来解决. 最初的时候没有考虑到数据范围.稍加分析,x,y最大 ...

  5. c语言大小写字母互换1005,1005 Jugs,1005jugs

    1005 Jugs,1005jugs 辗转相减,新手入门题.两个容量的灌水题,无所谓最优解. 1 #include 2 3 intmain(){4 intA,B,T,sA,sB;5 while(sca ...

  6. linux脚本简介,Linux Shell脚本简介

    Shell 诞生于 Unix,是与 Unix/Linux 交互的工具,单独地学习 Shell 是没有意义的,请先参考Unix/Linux入门教程,了解 Unix/Lunix 基础. 近几年来,Shel ...

  7. poj题目详细分类及算法推荐题目

    DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题  ...

  8. ACM POJ 题目分类(完整整理版本)

    DP: 1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题   ...

  9. POJ ZOJ题目分类

    POJ,ZOJ题目分类(多篇整合版,分类很细致,全面) 标签: 题目分类POJ整理 2015-04-18 14:44 1672人阅读 评论(0) 收藏 举报 本文章已收录于: 分类: ACM资料(5) ...

  10. POJ,ZOJ题目分类(多篇整合版,分类很细致,全面)

    水题: 3299,2159,2739,1083,2262,1503,3006,2255,3094 初级: 一.基本算法:        (1)枚举 (1753,2965)       (2)贪心(13 ...

最新文章

  1. 【BZOJ1497】【NOI2006】最大获利
  2. webform开发经验(一):Asp.Net获取Checkbox选中的值
  3. oracle存储过程模板
  4. C++中的类模板详细讲述
  5. 【学习笔记】硬件设备选型
  6. 卡罗林斯卡学院(Karolinska Institute)
  7. linux系统上传代码到gitlab服务器
  8. 2016年物联网市场5大趋势
  9. java EE 监听器
  10. Oracle/PLSQL While Loop
  11. python 基础干货 01
  12. 【English】20190513
  13. html图片点击加边框颜色代码,用HTML代码给图片添加边框方法
  14. 中水处理设备:中水回用的三种主处理方法及其比较
  15. 如何测试app启动时间?
  16. 注册Netgear DDNS账号的操作
  17. Eclilpse插件安装
  18. Flash:设置文档、散件、元件属性
  19. 2022-2028中国分期付款解决方案市场现状研究分析与发展前景预测报告
  20. Android电池电量检测

热门文章

  1. 自尊是人生的高尚境界
  2. HTML5实现手机QQ表情功能
  3. 红帽8LINUX命令行使用技巧
  4. 计算机专业必读哪些经典书籍?
  5. 十大游戏开发引擎优缺点对比
  6. “Defaulting to user installation because normal site-packages is not writeable“
  7. 健康小贴士:喝酒时别点哪些菜_新闻中心_新浪网
  8. 洛谷 P3324 [SDOI2015]星际战争 二分答案+网络流
  9. PowerBI 开发 第22篇:发现异常(Find Anomalies)
  10. 考拉兹猜想(Python版)