FOJ Problem 2221 RunningMan
2016-04-14 16:35
309 查看
Problem Description
ZB loves watching RunningMan! There's a game in RunningMan called 100 vs 100.
There are two teams, each of many people. There are 3 rounds of fighting, in each round the two teams send some people to fight. In each round, whichever team sends more people wins, and if the two teams send the same amount of people, RunningMan team wins.
Each person can be sent out to only one round. The team wins 2 rounds win the whole game. Note, the arrangement of the fighter in three rounds must be decided before the whole game starts.
We know that there are N people on the RunningMan team, and that there are M people on the opposite team. Now zb wants to know whether there exists an arrangement of people for the RunningMan team so that they can always win, no matter how the opposite team
arrange their people.
Input
The first line contains an integer T, meaning the number of the cases. 1 <= T <= 50.
For each test case, there's one line consists of two integers N and M. (1 <= N, M <= 10^9).
Output
For each test case, Output "Yes" if there exists an arrangement of people so that the RunningMan team can always win. "No" if there isn't such an arrangement. (Without the quotation marks.)
这一题关键在于分析,你赢的充分必要条件是什么?就是三轮比赛你任意挑选两轮出来你不能都输,也就是说任意拿两轮比赛你都得赢一到两场,这是一个充分必要条件,所以反过来当你任选两轮不会出现两轮都输的话,最后你一定会赢。所以问题就简化了,从三轮比赛降为两轮。现在假设敌方队任意两轮的总人数都等于题目中的M,这是一种最极端的做法,可以让敌方队这两轮的人数最多。
Sample Input
2
100 100
200 100
Sample Output
No
Yes
这一题关键在于分析,你赢的充分必要条件是什么?就是三轮比赛你任意挑选两轮出来你不能都输,也就是说任意拿两轮比赛你都得赢一到两场,这是一个充分必要条件,所以反过来当你任选两轮不会出现两轮都输的话,最后你一定会赢。所以问题就简化了,从三轮比赛降为两轮。现在假设敌方队任意两轮的总人数都等于题目中的M,这是一种最极端的做法,可以让敌方队这两轮的人数最多。
(1)当M为偶数时,即敌方队的人数为偶数时,设2*k=M;
则running man队的三轮人数为:
k, k, k-1
这样的安排会使敌方队任选两轮,不可能都赢。且这是最优的了
所以N>=(k+k+k-1);
(2)当M为奇数时, 即敌方队的人数为奇数时,设2*K+1=M;
则running man队的三轮人数为:
k, k, k
这样的安排会使敌方队任选两轮,不可能都赢。且这是最优的了
所以N>=(k+k+k);
AC代码:
ZB loves watching RunningMan! There's a game in RunningMan called 100 vs 100.
There are two teams, each of many people. There are 3 rounds of fighting, in each round the two teams send some people to fight. In each round, whichever team sends more people wins, and if the two teams send the same amount of people, RunningMan team wins.
Each person can be sent out to only one round. The team wins 2 rounds win the whole game. Note, the arrangement of the fighter in three rounds must be decided before the whole game starts.
We know that there are N people on the RunningMan team, and that there are M people on the opposite team. Now zb wants to know whether there exists an arrangement of people for the RunningMan team so that they can always win, no matter how the opposite team
arrange their people.
Input
The first line contains an integer T, meaning the number of the cases. 1 <= T <= 50.
For each test case, there's one line consists of two integers N and M. (1 <= N, M <= 10^9).
Output
For each test case, Output "Yes" if there exists an arrangement of people so that the RunningMan team can always win. "No" if there isn't such an arrangement. (Without the quotation marks.)
这一题关键在于分析,你赢的充分必要条件是什么?就是三轮比赛你任意挑选两轮出来你不能都输,也就是说任意拿两轮比赛你都得赢一到两场,这是一个充分必要条件,所以反过来当你任选两轮不会出现两轮都输的话,最后你一定会赢。所以问题就简化了,从三轮比赛降为两轮。现在假设敌方队任意两轮的总人数都等于题目中的M,这是一种最极端的做法,可以让敌方队这两轮的人数最多。
Sample Input
2
100 100
200 100
Sample Output
No
Yes
这一题关键在于分析,你赢的充分必要条件是什么?就是三轮比赛你任意挑选两轮出来你不能都输,也就是说任意拿两轮比赛你都得赢一到两场,这是一个充分必要条件,所以反过来当你任选两轮不会出现两轮都输的话,最后你一定会赢。所以问题就简化了,从三轮比赛降为两轮。现在假设敌方队任意两轮的总人数都等于题目中的M,这是一种最极端的做法,可以让敌方队这两轮的人数最多。
(1)当M为偶数时,即敌方队的人数为偶数时,设2*k=M;
则running man队的三轮人数为:
k, k, k-1
这样的安排会使敌方队任选两轮,不可能都赢。且这是最优的了
所以N>=(k+k+k-1);
(2)当M为奇数时, 即敌方队的人数为奇数时,设2*K+1=M;
则running man队的三轮人数为:
k, k, k
这样的安排会使敌方队任选两轮,不可能都赢。且这是最优的了
所以N>=(k+k+k);
AC代码:
# include <cstdio> using namespace std; int main(){ int n, t, m, i, j, k, x; scanf("%d", &t); for(i=1; i<=t; i++){ scanf("%d%d", &n, &m); if(m%2==0){ x=m*3/2-1; } else{ x=m/2*3; } if(n>=x){ printf("Yes\n"); } else{ printf("No\n"); } } return 0; }
相关文章推荐
- EditView的监听者TextWatcher
- python常用的一些东西——sys、os等
- androd欢迎页播放视频和广告页面
- 10的阶乘
- 淘宝封装的一款ui 非常不错
- 关于委托,事件和类的设计准则
- 一个flag
- 10个随机数的和
- 【JS】:JS实现页面的刷新,后退和前进
- ASP.NET自定义控件开发示例(一)
- 【LeetCode】96. Unique Binary Search Trees 解法及注释
- <css 十五>尺寸设置
- 九种求和方法
- C#开发微信门户及应用(32)--微信支付接入和API封装使用
- js最新手机号码、电话号码正则表达式
- MySQL入门很简单: 4 创建 修改删除表
- 转]解析C语言中的sizeof
- ftp服务器简单配置
- ANT 、Junit、JunitReport、Spring、MyBatis
- ECSHOP手机访问和电脑访问效果一样