FZU Problem 2221 RunningMan(思维考查)——第六届福建省大学生程序设计竞赛-重现赛

此文章可以使用目录功能哟↑(点击上方[+])

 FZU Problem 2221 RunningMan

Accept: 0    Submit: 0
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 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.)

 Sample Input

2
100 100
200 100

 Sample Output

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.

 Problem Idea

解题思路:

【题意】
两个队伍(其中一队为RunningMan)进行三轮制比赛

比赛规则如下:

①每轮比赛中,人数较多的一方获胜,人数相同时算RunningMan这队获胜

②参赛的每个人最多只能参加一轮比赛

③比赛采取三局两胜制,即赢了两轮比赛的队伍获胜

④三轮比赛的人数安排必须在总的比赛开始前给出,且不能更换

⑤显然,比赛开始前,每一队都不知道对方的人数安排情况

现在已知RunningMan队有n个人,另一队有m个人,问RunningMan队是否必定能够获得比赛最终的胜利

【类型】
思维考查

【分析】

那么,在不知道对手如何安排人数的前提下,要想必胜,RunningMan的唯一选择就是每轮上场人数相同

这样就能应付对手可能安排某一轮人数多,某一轮人数少的情况,使得就算让对手赢也不能赢得太轻松,要尽可能地消耗对方人数

所以我们暂时假设RunningMan每轮上场人数为k


这就相当于,即便对手知道RunningMan队如何安排人数,但依旧是输

而我们之前已经知道RunningMan每轮上场人数为k

那对手要赢就要做到至少两场人数为k+1,更明智的,对手会放弃一轮,而把己方所有人投到某两轮中放手一搏

考虑到人是无法分割的整体,因此,我们对对手方的人数m进行奇偶性分类讨论:

⒈当m为偶数时,因为RunningMan队是平均分配人数的,所以对手方两轮人数分别为k,k(m=k+k,就算不是k,k也不要紧,后面接着分析)

此时RunningMan要想必定获胜且用的总人数最少,人数安排应该是k,k,k-1

这样的话,对手最多可以赢一场,即k>k-1,然后对手只剩k个人,无法赢另外两场,显然对手不会花更多的人去赢k-1的这轮,人越多越浪费

⒉当m为奇数时,对手方人数安排为k,k-1(m=k+k-1)

那么,RunningMan的人数安排为k-1,k-1,k-1就足够了

分析完毕

【时间复杂度&&优化】
O(1)

题目链接→FZU Problem 2221 RunningMan

 Source Code

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 1005;
const int M = 1005;
const int inf = 1000000007;
const int mod = 1000003;
int main()
{
    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        if(m%2&&n>=m/2*3||m%2==0&&n>=m/2*3-1)
            puts("Yes");
        else
            puts("No");
    }
    return 0;
}
菜鸟成长记

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值