cf A. Card Game

A. Card Game

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

Two players decided to play one interesting card game.

There is a deck of n cards, with values from 11 to n. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player has at least one card.

The game goes as follows: on each turn, each player chooses one of their cards (whichever they want) and puts on the table, so that the other player doesn't see which card they chose. After that, both cards are revealed, and the player, value of whose card was larger, takes both cards in his hand. Note that as all cards have different values, one of the cards will be strictly larger than the other one. Every card may be played any amount of times. The player loses if he doesn't have any cards.

For example, suppose that n=5�=5, the first player has cards with values 22 and 33, and the second player has cards with values 11, 44, 55. Then one possible flow of the game is:

  • The first player chooses the card 33. The second player chooses the card 11. As 3>13>1, the first player gets both cards. Now the first player has cards 11, 22, 33, the second player has cards 44, 55.

  • The first player chooses the card 33. The second player chooses the card 44. As 3<43<4, the second player gets both cards. Now the first player has cards 11, 22. The second player has cards 33, 44, 55.

  • The first player chooses the card 11. The second player chooses the card 33. As 1<31<3, the second player gets both cards. Now the first player has only the card 22. The second player has cards 11, 33, 44, 55.

  • The first player chooses the card 22. The second player chooses the card 44. As 2<42<4, the second player gets both cards. Now the first player is out of cards and loses. Therefore, the second player wins.

Who will win if both players are playing optimally? It can be shown that one of the players has a winning strategy.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1001≤�≤100). The description of the test cases follows.

The first line of each test case contains three integers n, k1�1, k2�2 (2≤n≤100,1≤k1≤n−1,1≤k2≤n−1,k1+k2=n2≤�≤100,1≤�1≤�−1,1≤�2≤�−1,�1+�2=�) — the number of cards, number of cards owned by the first player and second player correspondingly.

The second line of each test case contains k1�1 integers a1,…,ak1�1,…,��1 (1≤ai≤n1≤��≤�) — the values of cards of the first player.

The third line of each test case contains k2�2 integers b1,…,bk2�1,…,��2 (1≤bi≤n1≤��≤�) — the values of cards of the second player.

It is guaranteed that the values of all cards are different.

Output

For each test case, output "YES" in a separate line, if the first player wins. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower).

Example

input

2

2 1 1

2

1

5 2 3

2 3

1 4 5

output

YES

NO

Note

In the first test case of the example, there is only one possible move for every player: the first player will put 22, the second player will put 11. 2>12>1, so the first player will get both cards and will win.

In the second test case of the example, it can be shown that it is the second player who has a winning strategy. One possible flow of the game is illustrated in the statement.

e,相信这么长的东西大家也不想看,所以让我给大家分享一下我自己翻译后的题目(更好理解了)
有n张牌,编号1~n,将牌发给两位玩家(每个人至少一张)
每回合两人各出一张牌,比较这两个数字,数字大的人拿走这两张牌。谁手上没牌了谁就输了
如果两个人都用最优策略,谁会赢?玩家1胜利输出YES,否则输出NO

啊这类题目咱们一般有一种称号,水题,最优策略也就是一直出自己最大的牌
对于这道题本人想出了两种写法
方法一:比较2人谁手上最大的牌更大
代码送上
#include <bits/stdc++.h>
using namespace std;
int T,n,k1,k2,z,Max1,Max2;
int main(){
    cin>>T;
    while(T--){
        Max1=0,Max2=0;
        cin>>n>>k1>>k2;
        for(int i=0;i<k1;i++){
            cin>>z;
            if(z>Max1) Max1=z;
        }
        for(int i=0;i<k2;i++){
            cin>>z;
            if(z>Max2) Max2=z;
        }
        if(Max1>Max2) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

方法2:看看谁拿着n(n一定是最大的牌)
代码送上
#include <bits/stdc++.h>
using namespace std;
int T,n,k1,k2;
int main(){
    cin>>T;
    while(T--){
        bool flag=0;
        cin>>n>>k1>>k2;
        for(int i=0;i<k1;i++){
            cin>>z;
            if(z==n){
                flag=1;
                break;
            }
        }
        for(int i=0;i<k2;i++) cin>>z;
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
Tips:本题多测
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值