[Use the map data structure

1> the correct answer

Exam, n m individual questions,

Give you the full number of people and the number of full-wrong

Lexicographically smallest answer determined sequence, no outputs -1

 

My idea: Category talk

Each count of papers, see him and his opposite roll equals p and q are possible

If p || q, then either you have the correct answer in the examination paper in either no solution

p == q == 0, then find the answer there have been a series of fine

Correct answer is letter-only tree, the line 60 -> 90 rows

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int n,m,p,q;
const int N=30003,M=503;
string s[N];
map <string ,int > mp;
string fz(string a)
{
    for(int i=0;i<m;i++)
        if(a[i]=='Y') a[i]='N';
        else a[i]='Y';
    return a;
}
void print(string ans)
{
    cout<<ans;
    exit(0);
}
string ck;
void dfs(int pos)
{
    if(pos==m)
    {
        if(mp[ck]==0 && mp[(fz(ck))]==0) print(ck);
        return ; 
    }
    
    ck[pos]='N';
    dfs(pos+1);
    ck[pos]='Y';
    dfs(pos+1);
}
int sum;
int main()
{
    cin>>n>>m>>p>>q;
    for(int i=1;i<=n;i++)
        cin>>s[i],mp[s[i]]++;
    sort(s+1,s+n+1);
    n=unique(s+1,s+n+1)-s-1;
    
    if(p || q)
    {
        for(int i=1;i<=n;i++)
        {
            int cnt=mp[s[i]];
            if(cnt==p && mp[fz(s[i])]==q) s[sum++]=s[i];
            else if(cnt==q && mp[fz(s[i])]==p) s[sum++]=fz(s[i]); 
        }
        if(sum)
            sort(s,s+sum),print(s[0]);
        else cout<<"-1"<<endl;
    }
    else
    {
        ck=s[1];
        dfs(0);
        cout<<"-1"<<endl;
    }
    
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/xwww666666/p/11427921.html