ZOJ 3961 Let's Chat (Analog)

Posted by Graphi on Mon, 25 Nov 2019 21:28:40 +0100

Portal

Give you a few people, and then the next line i corresponds to the person who answers the ith question, and finally ask who answers the questions.

With a map, save the name and number, the number of questions answered will also be converted into binary system, and then into decimal system. In this way, the questions answered by each person will correspond to a number, and the string of binary system will also be converted into decimal system when asking, so that the comparison will be more convenient. For each inquiry, a unique person will output the name, otherwise... Hey hey hey

#include <bits/stdc++.h>
using namespace std;
map<string,int>s;
string sx[220];
int x[220][220];
int main()
{
    //freopen("in.txt","r",stdin);
    cin.tie(0);
    cout.tie(0);
    int t,n,q,c,d;
    cin >> t;
    while(t--)
    {
        cin >> n >> q;
        memset(x,0,sizeof(x));
        s.clear();
        cin >> c;
        for(int i = 0;i < c; i++)
        {
            cin >> sx[i];
            s[sx[i]] = 0;
        }
        for(int i = 0;i < q; i++)
        {
            cin >> d;
            for(int j = 0;j < d; j++)
            {
                string tmp;
                cin >> tmp;
                s[tmp] += pow(2.0,i);
            }
        }
        while(n--)
        {
            int ans = 0,flag = 0;
            for(int i = 0;i < q; i++)
            {
                int tp;
                cin >> tp;
                if(tp == 1)
                {
//                    cout << i << " " << tp << " ";
                    ans += pow(2.0,i);
                }

            }
            string anss;
            for(int i = 0;i < c; i++)
            {
                if(s[sx[i]] == ans)
                {
                    anss = sx[i];
                    flag++;
                }
            }
            if(flag == 1)
            {
                cout << anss << endl;
                continue;
            }
            cout << "Let's go to the library!!" << endl;
        }
    }
    return 0;
}