浙江省赛C题 What Kind of Friends Are You?

Alice and Bob are playing yet another game of stones. The rules of this game are as follow:

  • The game starts with n piles of stones indexed from 1 to n. The i-th pile contains ai stones and a special constraint indicated as bi.
  • The players make their moves alternatively. The allowable moves for the two players are different.
  • An allowable move of Bob is considered as removal of some positive number of stones from a pile.
  • An allowable move of Alice is also considered as removal of some positive number of stones from a pile, but is limited by the constraint bi of that pile.
    • If bi = 0, there are no constraints.
    • If bi = 1, Alice can only remove some odd number of stones from that pile.
    • If bi = 2, Alice can only remove some even number of stones from that pile.
    Please note that there are no constraints on Bob.
  • The player who is unable to make an allowable move loses.

Alice is always the first to make a move. Do you know who will win the game if they both play optimally?

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1 ≤ n ≤ 105), indicating the number of piles.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), indicating the number of stones in each pile.

The third line of each test case contains n integers b1, b2, ..., bn (0 ≤ bi ≤ 2), indicating the special constraint of each pile.

It is guaranteed that the sum of n over all test cases does not exceed 106.

We kindly remind you that this problem contains large I/O file, so it's recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.

Output

For each test case, output "Alice" (without the quotes) if Alice will win the game. Otherwise, output "Bob" (without the quotes).

Sample Input
3
2
4 1
1 0
1
3
2
1
1
2
Sample Output
Alice
Bob
Bob
Hint

For the first test case, Alice can remove 3 stones from the first pile, and then she will win the game.

For the second test case, as Alice can only remove some even number of stones, she is unable to remove all the stones in the first move. So Bob can remove all the remaining stones in his move and win the game.

For the third test case, Alice is unable to remove any number of stones at the beginning of the game, so Bob wins.



分析:题意就是给出每道题答对人的姓名,然后给出查询的名单,进行匹配看有没有唯一的人存在。把查询的几个整数变成字符串然后进行匹配,看看最后数量是不是唯一即可。PS:这次写的及其不优雅,看个思路主要,别喷。

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    string a;

    while(t--)
    {

        set<string> st;
        st.clear();

        map<string,string> mp;
        map<string,string> ::iterator it;

        int m;
        int n;
        cin>>m>>n;

        int n2,k;

        cin>>n2;

        for(int i=0; i<n2; i++)
        {
            cin>>a;
            mp[a]="0";
        }

        for(int i=1; i<=n; i++)
        {
            cin>>k;
            while(k--)
            {
                cin>>a;
                if(i==1) mp[a]='1';
                else mp[a]+='1';
            }
            for(it=mp.begin(); it!=mp.end(); it++)
            {
                if((it->second).length()!=i)
                {
                    it->second +="0";
                }
            }
        }

        char j1;

        for(int i=0; i<m; i++)
        {
            st.clear();
            bool ok=0;
            string t;
            for(int j=0; j<n; j++)
            {
                cin>>j1;
                t+=j1;
            }

            for(it=mp.begin(); it!=mp.end(); it++)
            {
                if(it->second == t)
                {
                    st.insert(it->first);

                    ok=1;
                }
            }

            if(ok==0 ||st.size()!=1)
            {
                cout<<"Let's go to the library!!"<<endl;
                continue;
            }


            for(it=mp.begin(); it!=mp.end(); it++)
            {
                if(it->second == t )
                {
                    st.insert(t);
                    cout<<it->first<<endl;
                }
            }


        }

    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值