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. | ZB最近迷上了《Running Man》(韩)!跑男里有个游戏叫100 vs 100。 现在有两支队伍,每支队伍有若干人。三回合较量中,每轮两支队伍分别派出若干人比试。每回合中,派出人数较多的队伍获胜,如果两支队伍人数相同,则跑男队获胜。每人只能上场一次,三局两胜。注意,三回合的人数安排必须在游戏开始前决定。 我们知道跑男队有N人,并且敌方队伍有M人。现在ZB想要知道跑男队是否存在一种必胜的排法,让对手无可奈何。 |
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). | 第一行有一个整数T,表示样例的数量。1 <= T <= 50。 每个测试样例只有一行,每行两个整数N、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.) | 对于每个测试样例,如果存在跑男队必胜队排法则输出"Yes",否则输出"No"。(输出没有引号。) |
Sample Input- 输入样例 | Sample Output- 输出样例 |
2 100 100 200 100 | No Yes |
Hint | 提示 |
In the second example, the RunningMan team can arrange 60, 60, 80 people for the three rounds. No matter how the opposite team arrange their 100 people, they cannot win. | 对于每个测试样例,如果存在跑男队必胜队排法则输出"Yes",否则输出"No"。(输出没有引号。) |
【题解】
注意人数是>=1的。
那么对于敌方队伍来说,最优的策略就是:赢最少的,输最多的,剩下看脸。
所以这里设:
跑男队为 X = 3X + C 敌方队伍为 Y = 3Y + C
为了对敌方队伍在第一波造成最大的消耗,这里的X则尽可能大,所以C=0。
或者说跑男队的组合可以以不变应万变,可以直接当成X = 3X。
(懒癌发作,证明略)
然后写出敌方队伍最优策略下跑男队还能获胜的式子
Y-(Y+1) ≤ (X-X)/2
化简得:
2Y-2 ≤ X+X
Y-1 ≤ 2 X (懒癌发作)
Y-1 ≤ (2/3)X
注意这里都是数学运算,int的除法会出现精度问题,可以用double解决。
或者化成整数形式3*Y ≤ 2*X+3 (int会越界,最大值40亿,int最大值21亿+,可以使用unsigned int或 __int64,并且使用无符号的时候注意减法运算)
【代码 C++】
#include<cstdio>
int main(){
unsigned int x, y, t;
scanf("%u", &t);
while (t--){
scanf("%u%u", &x, &y);
if ( * y <= * x + ) puts("Yes");
else puts("No");
}
return ;
}
FZU 2221