文章标题 Gym100971 L :Chess Match

Chess Match

Description

standard input/output
Statements

Two best chess teams in the world are preparing to the match against each other. Both teams have n players. Each player has a rating, and the player with the higher rating always wins. Ratings of the players in the first team are a1, a2, …, an, and in the second team — b1, b2, …, bn. There are no players with equal ratings in both teams.

The chess match between two teams consists of n games, called the games on the first, second, …, n-th board. Before the match captains of both teams must decide which player will play on which board. When they do that, they don’t know the opponent’s choice.

After that a single game is played on each board. The team with the higher score wins.

For both teams, determine if it can win the match.

Input

The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of players in each team.

The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) — the ratings of the players in the first team.

The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) — the ratings of the players in the second team.

All ai and bi are pairwise distinct.

Output

Output «First» if only first team can win, «Second» if only second team can win, «Both» if both teams can win, and «None» if there will be a draw in any case. Don’t output quotes.

Sample Input

Input
5
1 3 5 7 9
2 4 6 8 10

Output
Both

Input
5
1 2 3 4 5
6 7 8 9 10

Output
Second

Input
4
9001 9002 1 3
8 6 4 2

Output
First

Input
2
1 1000000000
10000 100000

Output
None
题意:有两个队伍,每个队伍有n个队员,两个队伍中每个队员的等级都不一样,先要求两个队伍比赛,每个队伍每次选出一个队员,等级高的就能赢得这场比赛,最后赢的比赛多的就能赢得这场比赛。如果两个队伍都有可能赢得对方就输出both,只有其中一个队伍能赢,就输出相应的队伍,如果两个队伍都不能赢得对方,就输出none。
分析:直接模拟,先将两个都排序,然后找到每个第一个能应的第一个队员,然后一次往后比,看最终最多能赢得多少场。最后看两个队伍的情况输出结果
代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<math.h>
#include<map>
#include<queue> 
#include<algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
int a[200005];
int b[200005];
int main ()
{
    int n;
    while (scanf ("%d",&n)!=EOF){
        for (int i=0;i<n;i++){
            scanf ("%d",&a[i]); 
        }
        for (int i=0;i<n;i++){
            scanf ("%d",&b[i]); 
        }
        sort (a,a+n);//先排序
        sort (b,b+n);
        int flag_a=0,flag_b=0;
        int place=upper_bound (a,a+n,b[0])-a;//先看a的情况,从a中找到第一个大于b第一个队员等级的
        int k=0;
        int cnt=0;
        for (int i=place;i<n;i++){
            if (a[i]>b[k]){//如果能大于就cnt++,b的位置往后移
                cnt++;
                k++;
            }
        }
        if (cnt>n/2) flag_a=1;//如果a能赢得比赛,flag定为1
        else {
            if (n%2==0&&cnt<n/2) flag_a=-1;
            else if (n%2==1&&cnt<=n/2) flag_a=-1;
        }
        k=0;//b的与a的做法相似
        cnt=0;
        place=upper_bound (b,b+n,a[0])-b;
        for (int i=place;i<n;i++){
            if (b[i]>a[k]){
                cnt++;
                k++;
            }
        }
        if (cnt>n/2) flag_b=1;
        else {
            if (n%2==0&&cnt<n/2) flag_b=-1;
            else if (n%2==1&&cnt<=n/2) flag_b=-1;
        }
        //最后输出结果
        if (flag_a==1&&flag_b==1) printf ("Both\n");
        else if (flag_a==1) printf ("First\n");
        else if (flag_b==1) printf ("Second\n");
        else if (flag_a==0&&flag_b==0) printf ("None\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值