FOJ Problem 2221 RunningMan

来源:互联网 发布:ubuntu装入u盘 编辑:程序博客网 时间:2024/05/21 18:00
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代码:


# 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;}


0 0
原创粉丝点击