[C++] 纯文本查看 复制代码 #include<iostream>
#include<map>
#include<cstring>
using namespace std;
struct p{
int id;
string sen;
}b[100001];
map<string,int> ma;
string a[100001];
string d[]=
{
"Today is Sunday.",
"Today is Monday.",
"Today is Tuesday.",
"Today is Wednesday.",
"Today is Thursday.",
"Today is Friday.",
"Today is Saturday.",
};
int n,m,q;
int T,F,ans,ansf;
int TF[1001];
bool pdtf(int id,bool fl)
{
if(TF[id]==-1)
{
TF[id]=fl;
if(fl) ++T;
else ++F;
}
else
return TF[id]!=fl;
if(F>n||T>m-n) return 1;
return 0;
}
void pd(int id,int day)
{
T=F=0;
memset(TF,-1,sizeof TF);
for(int i=1;i<=q;i++)
{
int flag=b[i].sen.find("I am guilty.");
if(flag!=-1)
{
if(pdtf(b[i].id,b[i].id==id)) return;
}
flag=b[i].sen.find("I am not guilty.");
if(flag!=-1)
{
if(pdtf(b[i].id,b[i].id!=id)) return;
}
flag=b[i].sen.find(" is guilty.");
if(flag!=-1)
{
string tmp=b[i].sen;
tmp.erase(flag,11);
if(pdtf(b[i].id,ma[tmp]==id)) return;
}
flag=b[i].sen.find(" is not guilty.");
if(flag!=-1)
{
string tmp=b[i].sen;
tmp.erase(flag,15);
if(pdtf(b[i].id,ma[tmp]!=id)) return;
}
flag=b[i].sen.find("Today is ");
if(flag!=-1)
{
if(pdtf(b[i].id,d[day]==b[i].sen)) return;
}
}
if(ans!=0&&ans!=id) ansf=1;
ans=id;
}
int main()
{
cin>>n>>m>>q;
for(int i=1;i<=n;i++)
{
cin>>a[i];ma[a[i]]=i;
}
for(int i=1;i<=q;i++)
{
string name,s;
cin>>name;
name.erase(name.length()-1);
getline(cin,b[i].sen);
b[i].sen.erase(0,1);
if(b[i].sen[b[i].sen.length()-1]=='\n'||b[i].sen[b[i].sen.length()-1]=='\r')
b[i].sen.erase(b[i].sen.length()-1);
b[i].id=ma[name];
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<7;j++)
{
pd(i,j);
/*if(ansf==1)
{
cout<<"Cannot Determin";
return 0;
}*/
}
}
if(ans==0) cout<<"Impossible";
else cout<<a[ans];
return 0;
} |