【ZOJ1003】Crashing Balloon(DFS)
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)的更多相关文章
- 【算法】深度优先搜索(dfs)
突然发现机房里有很多人不会暴搜(dfs),所以写一篇他们能听得懂的博客(大概?) PS:万能 yuechi ---- 大法师怎么能不会呢?! 若有错误,请 dalao 指出. 前置 我知道即使很多人都 ...
- 【搜索】棋盘问题(DFS)
Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...
- 【算法】深度优先搜索(DFS)III
1. DFS生成排列 众所周知,1,2…n的排列一共有n!个,因此生成全排列至少需要n!的时间复杂度.如果用循环来生成排列,当n稍大时,内外循环会非常之多.可以用DFS模拟解决,生成0 … n-1的排 ...
- 【UVa】208 Firetruck(dfs)
题目 题目 分析 一开始不信lrj的话,没判联通,果然T了. 没必要全部跑一遍判,只需要判断一下有没有点与n联通,邻接表不太好判,但无向图可以转换成去判n与什么联通. 关于为什么要判,还是因为 ...
- 【HDOJ6628】permutation 1(dfs)
题意:求1到n的排列中使得其差分序列的字典序为第k大的原排列 n<=20,k<=1e4 思路:爆搜差分序列,dfs时候用上界和下界剪枝 #include<bits/stdc++.h& ...
- 【Luogu】P3761城市(dfs)
题目链接 emmm我思维好水…… 想了一会lct发现好像不对,然后开始转DP稍微有一点思路,然后看了题解…… 首先可以枚举边,然后原树被你拆成了两个子树. 设D1D2是两个子树的直径,W1W2是子树内 ...
- CJOJ 1071 【Uva】硬币问题(动态规划)
CJOJ 1071 [Uva]硬币问题(动态规划) Description 有n种硬币,面值分别为v1, v2, ..., vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为 ...
- 【Luogu1273】有线电视网(动态规划)
[Luogu1273]有线电视网(动态规划) 题面 题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端, ...
- 【Luogu2458】保安站岗(动态规划)
[Luogu2458]保安站岗(动态规划) 题面 题目描述 五一来临,某地下超市为了便于疏通和指挥密集的人员和车辆,以免造成超市内的混乱和拥挤,准备临时从外单位调用部分保安来维持交通秩序. 已知整个地 ...
随机推荐
- 【python】3.x,string与bytes的区别(文本,二进制数据)
Python 3对文本和二进制数据作了更为清晰的区分.文本总是Unicode,由str类型表示, 二进制数据则由bytes类型表示. 不能拼接字符串和字节包,也无法在字节包里搜索字符串(反之亦然),也 ...
- 第九章 硬件抽象层:HAL
这一章介绍HAL,全称为Hardware Abstract Layer,即硬件抽象层,它是建立在Linux驱动之上的一套程序库,程序库并不属于Linux内核,而是属于Linux内核层之上的应用层.为A ...
- lucene5学习 - 索引基本操作(创建,查询,更新,删除,分页)
package lucene5; import java.io.IOException; import java.nio.file.Paths; import java.text.SimpleDate ...
- C语言程序设计第7堂作业
一.本次课主要内容: 本次以计算圆柱体体积为例,通过定义体积计算功能的函数和主函数调用的例子,引出函数定义的一般形式:函数首部加函数体,且在函数结尾处通过return 语句返回结果.本节要重 ...
- Java和eclipse常用操作
eclipse: ctrl+F10 显示行号 ctrl+shift+F 自动对齐 ctrl+/ 注释 java: jar包: Manifest-Version - 指定清单文件的版本号 Main-Cl ...
- 64位系统下找不到office 32位组件
如果系统式64位的,而装的是32位的office软件,在运行栏中输入命令:dcomcnfg,打开组件服务管理窗口,但是却发现找不到Microsoft Excel程序, 这主要是64位系统的问题,exc ...
- NOIP 考前 队列复习
BZOJ 1127 #include <cstdio> #include <cstring> #include <iostream> #include <al ...
- centos 7 lamp (linux+apache+mysql+php)开发环境搭建(转+原创)
准备篇:CentOS 7.0系统安装配置图解教程 http://www.jb51.net/os/188487.html 一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是fi ...
- LayaAir引擎——(九)
var h = new Array(); var j = new Array(); var xbCursor = 0; function xbinit() { xbinitName(); xbRect ...
- javascript常用数组算法总结
1.数组去重 方法1: JavaScript //利用数组的indexOf方法 function unique (arr) { var result = []; for (var i = 0; i & ...