【算法】算法之美—Crashing Balloon

ZOJ-1003-Crashing-Balloon 题目描述 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 阅读详情

题目概述:Crashing Balloon


  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.

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,有两个人参与.一但开始,两个人就疯狂的踩气球,时间到就结束了(也许就10s),把他们各自踩破的球上的编号乘起来,分别是M,N,那么排名自然揭晓了

  可是分数低的人不服气,想申诉.现在问题来了,怎么申诉呢?因为每个标号的球只有一个,所以加入B踩破的话,A就没办法踩了,申诉想要产生的矛盾就在这儿.现在假如分数是 343 49 ,343可以是踩了 7和49,49只能是踩49,他们两都同时必须要踩这个49,那么就产生矛盾了.所以49赢了.还有要是有人的分数,不能由1->100的数的成绩的出,算说假话,如果两个人都说假话,还是分高的赢.



题目分析

  有三种情况:

  (1)A,B没有矛盾,那么A赢

  (2)A,B怎么都会有矛盾,而且B说的是真话,那么B赢

  (3)A,B怎么都会有矛盾,而且B说的是假话,那么A赢




解题算法

  下面的源代码中,我对主要的代码都作了详细的注释,如题

#include < stdio.h>
int flagA,flagB;
int result ;
void dfs(int m,int n,int kk)    //运用了深度优先 的搜索策略
{
    int k =kk;
    if(m==1 && n==1)    //在两个数的所有各不相同的因子中,有因子能重新乘出给出的两个数,则A说了真话
    {
       flagA=1; //A说了真话
       return ;
    }
    if(n==1) //在两个数的所有各不相同的因子中,没有任何因子能重新乘出给出的两个数,则B说了真话
        flagB =1;   //B说了真话
    while( (k <  m || k <  n) && (k< 100) )
    {
       k++;
       /*
       *依次找出两个数所有各不相同的因子,如24和12的所有因子为 2,3,4,6,8,12 ,
        再在这些因子中搜索,看是否能重新乘出给出的两个数
       */
       if(m%k ==0)
       {
            dfs(m/k,n,k);
            if(flagA)
                return ;
       }
       if(n%k ==0 )
       {
            dfs(m,n/k,k);
            if(flagA)
                return ;
       }
    }
}
int main()
{
    int A,B,t;
    while(scanf("%d%d",&A,&B)!=EOF )
    {
        if(A <  B )  //保证A大B小
        {
            t=A;
            A=B;
            B=t;
        }
        flagA =0;   //先假定AB都说假话
        flagB =0;
        dfs(A,B,1); //判断AB矛盾         
        /*
        *要求:
        *较小者发起挑战,若较大者被证明说谎,较小者胜(较小者说真话,同时较大者说了假话);
        *若较大者可以成立,则较大者胜;
        *若较小者对自己的结果计算错误,也就是较小者不能成立,如因子中包含一个大于100的质数,则挑战不会举行,较大者胜
        */
        result =A;   
        if(flagA ==0 && flagB ==1)  //只有证明A说了假话,并且B说了真话,才算B赢
            result =B;
        printf("%d\n",result);
    }
    return 0;
}


本文出自 “成鹏致远” 博客,请务必保留此出处http://infohacker.blog.51cto.com/6751239/1195118

机器人嵌入式开发走向开源生态与标准化:从RTOS到ROS 2的实践 嵌入式开发是机器人系统的基石,实时操作系统(RTOS)与通信中间件构成其核心。随着开源生态的成熟,FreeRTOS、Zephyr等RTOS提供了硬件抽象与设备树机制,DDS等标准通信协议则让多节点协作变得松耦合、可复用。这种模式打破了传统“裸机+私有协议”的手工作坊式开发,显著降低重复造轮子的成本,提升团队协作与产品迭代效率。在移动底盘、机械臂等复合机器人场景中,MCU与MPU异构架构通过ROS 2和DDS实现分层协同,已成为主流选型。本文结合实际项目,解析开源生态与标准化如何从芯片到应用全链路重塑机器人嵌 阅读详情

相关推荐

CATIA二次开发CAA:(一)开发环境搭建

CATIA+CAA+RADE+VS2012

ysm1987的博客 1万+

ZOJ:1003 Crashing Balloon(DFS)

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

Rrrrya 392

MEG预处理-Brainstorm

Brainstorm下载和安装 去Brainstorm官网进行下载:打开网页后,点击左侧Download;在跳出来的界面中进行简单的注册,注册完成后可以进行下载 解压后得到“brainstorm3”的文件夹,里面包含Brainstorm工具包的所有文件,把这个文件夹放在某个路径如"E:\matlab_tools\brainstorm3"即可 同样在某个路径建立空的文件夹命名为:brainstorm_db用于工具包运行过程中自动存储生成的文件,所以这个文件中生成的数据不要手动移动删除 在Matlab中,把.

AxeChen的博客 6135

PCB模块化设计24——DCDC电源模块PCB布局布线设计规范

PCB模块化设计24——DCDC电源模块PCB布局布线设计规范

qq_31444421的博客 2万+

嵌入式Linux Qt/QML开发实战:从Buildroot配置到应用部署

本文详细介绍了嵌入式Linux Qt/QML开发全流程,从Buildroot系统配置、交叉编译工具链搭建到应用部署与调试。以RK3506开发板为例,提供实战指南,帮助开发者高效完成嵌入式应用开发,解决常见环境配置与性能优化问题。

m2n3o4p5的博客 231

Crashing Balloon因子的计算

碰撞气球 时间限制:2秒内存限制:65536 KB 每年6月1日的儿童节,都会有一个名为“爆气球”的电视节目。这个规则很简单。地面上有100个标有气球的气球,号码是1到100。裁判员喊道:“走吧!”这两名选手每人以1分开始比赛,用脚撞倒气球,同时把他们的分数乘以写在气球上的数字。一分钟后,小观众就可以把剩下的气球拿走,每个参赛者都会报告他自己的得分,即他坠毁的气球上的数字。非正式的赢家是宣...

qq_42728686的博客 540

u3d逆向学习之纯C内存读写与ImGui绘制(Android)

方法:需要在/proc/pid/maps文件查找模块名,一行行遍历所有内存,第一个参数为模块名,第二个参数为索引index(因为该模块会有多个,index为正序遍历第index个该模块),若找到了则使用。32位游戏的指针大小采用4字节,而64位游戏的指针大小采用8字节(这里需要注意),数据地址以16进制存储,使用unsigned long类型 ,该函数只有一个参数,数据地址,返回该地址的指针跳转地址。文件,比较其中的内容是否与传入的包名相同,如果相同,则返回该进程的PID。

zhoujunjie2004的博客 1695

ZOJ Problem Set - 1003Crashing Balloon

Crashing BalloonTime Limit: 1 Second      Memory Limit: 32768 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 ...

weixin_34384557的博客 221

避坑指南:LISFLOOD-FP模型数据单位、参数文件与results文件夹结果解析全攻略

本文详细解析了LISFLOOD-FP洪水模拟模型的关键应用环节,包括数据单位校验、参数文件优化及结果文件解读与可视化。特别针对常见的单位混淆问题,提供了从DEM到边界条件的全面校验方法,并深入剖析了.par参数文件的配置技巧,帮助用户避免模型崩溃和结果失真。

weixin_42533622的博客 244

9、从统计到电路:未来物理不可克隆函数的基础

本文探讨了物理不可克隆函数(PUF)的关键技术,包括补偿环境影响、处理相关工艺变化、身份映射和测试方法。提出了一种基于新测试统计量Q的方法,有效提升了PUF的熵值和安全性。通过实验验证,新方法能够显著区分不同芯片,并增强PUF在不同环境下的适应性和可靠性,为未来PUF的设计与应用提供了重要基础。

pluto的博客 122

ZOJ 1003 Crashing Ballon 解题思路

原题目内容 Crashing Balloon Time Limit: 2000 msMemory 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 t...

weixin_44517200的博客 477

[PCIe5.0] 3.4.1 Flow Control Initialization State Machine Rules

流控初始化是PCIe链路中每个虚拟通道(VC)启用的必经流程,分为FC_INIT1和FC_INIT2两个阶段,确保发送端与接收端的缓冲区信用值协商一致。

系统固件工程师 140

Crashing Balloon

Crashing BalloonTime limit: 1 Seconds   Memory limit: 32768K   Total Submit: 3366   Accepted Submit: 898   On every June 1st, the Childrens Day, there will be a game named "crashing balloon" on TV.

Kinglliam的专栏 1374

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

zoj1003 Crashing Balloon

//zoj1003 Crashing Balloon //Accepted 1003 C++ 00:00.06 440K #include #include using namespace std; i

fairylan的专栏 1410

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

ZOJ1003 Crashing Balloon

Time Limit: 2 Seconds Memory Limit: 65536 KBOn 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

松子茶的专栏 4477

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

[ZOJ] 1003 Crashing Balloon

/*-----------------------------------------  zoj1003 Crashing Balloon  road 2007/08/31     dfs     --------------------------------------------*/#include #include #define SWAP(x,y) do { x = x^y; y =

roadtang的专栏 999

[ZJU 1003] Crashing Balloon

ZOJ Problem Set - 1003 Crashing BalloonTime 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 v...

weixin_30646315的博客 149

Crashing Balloon problem Python

''' Created on 2013-1-22 @author: Administrator ''' flaga = 0 flagb = 0 def Check(a,b,number): global flaga global flagb if flaga==1: return 0 if a==1 and b==1: flaga

Json_Nie的专栏 688

ZOJ 1003 Crashing Balloon

每年的六一儿童节,电视上都会播放“撞气球”游戏。规则很简单,地上放着100个气球,上面标着1到100的数字。裁判喊“开始!”后,两名选手开始用脚撞气球,同时将自己的分数乘以撞到气球上的数字。一分钟后,小观众们可以把剩下的气球拿走,每个选手报告自己的得分,即撞到气球上的数字的乘积。宣布得分最高的选手就是非正式的获胜者。然而,争议不可避免地会出现,因此在争议解决之前,官方不会确定获胜者。声称得分较低的玩家有权挑战对手的得分。

wuqingshun314159的博客 1053

1003.Crashing Balloon

原题描述: 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.

CC 486

ZJU1003 Crashing Balloon - 踩气球

题目大意:输入两个正整数x,y,判断x和y能否由1到100之间的整数乘积组成,数字不能重复使用。分析:想不到很好的方法,一般考虑用搜索来解决。最初的时候没有考虑到数据范围。稍加分析,x,y最大可以达到100!,大约160位,只能使用高精度运算。搜索核心如下:void perform(bigNum x,int m)  //对于大数x,用不大于m的整数去试除{  if(x等

杨理垚的技术专栏 2137
上一篇: 【算法】算法之美—Fire Net
下一篇: 【ARM】s3c2440之gpio按键控制
成鹏致远
博客等级 码龄14年 50粉丝 132原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址