atcoder ABC 354-E题

atcoder ABC 354-E题

Problem Statement

Takahashi and Aoki are playing a game using Ncards. The front side of the i-th card has Ai​written on it, and the back side has Bi​ written on it. Initially, the N cards are laid out on the table. With Takahashi going first, the two players take turns performing the following operation:

Choose a pair of cards from the table such that either the numbers on their front sides are the same or the numbers on their back sides are the same, and remove these two cards from the table. If no such pair of cards exists, the player cannot perform the operation.
The player who is first to be unable to perform the operation loses, and the other player wins. Determine who wins if both players play optimally.

Constraints

1≤N≤18
1≤Ai​,Bi​≤109
All input values are integers.

Input

The input is given from Standard Input in the following
format:

N
A1​ B1​
A2​ B2​

AN​ BN​

Output

Print Takahashi if Takahashi wins when both players play optimally, and Aoki otherwise.

Sample Input 1

5
1 9
2 5
4 9
1 4
2 5

Sample Output 1

Aoki
If Takahashi first removes

the first and third cards: Aoki can win by removing the second and fifth cards.

the first and fourth cards: Aoki can win by removing the second and fifth cards.

the second and fifth cards: Aoki can win by removing the first and third cards.

These are the only three pairs of cards Takahashi can remove in his first move, and Aoki can win in all cases. Therefore, the answer is Aoki.

Sample Input 2

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

Sample Output 2

Takahashi

思路分析:

使用一个struct的vector来存储卡牌的正反面,再用一个vector来标记已经删除的卡牌,再用一个bool的常量来决定输出的是“Takahashi”还是“Aoki”。
此代码提交后过了11个测试点,样例都过了,如果有佬看见在评论区或者私信我帮我改一下,十分感谢。

code:

#include <iostream>
#include <vector>
using namespace std;
struct node{
    int a,c;
};
int n;
bool b=false;
int main(int argc, const char * argv[]) {
    cin>>n;
    vector<node>v(n);
    vector<bool>vi(n,false);
    for(int i=0;i<n;i++){
        cin>>v[i].a>>v[i].c;
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            if(i!=j&&(v[i].a==v[j].a)||(v[i].c==v[j].c)&&vi[i]==false&&vi[j]==false){
                vi[i]=true;
                vi[j]=true;
                b=true;
                if(i!=j&&(v[i].a==v[j].a)||(v[i].c==v[j].c)&&vi[i]==false&&vi[j]==false){
                    vi[i]=true;
                    vi[j]=true;
                    b=false;
                }
                else break;
            }
            else break;
        }
    if(!b){
        cout<<"Aoki"<<endl;
    }
    else if(b){
        cout<<"Takahashi"<<endl;
    }
    return 0;
}
  • 42
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值