侦探推理

题目链接

这是一道恶心至极的模拟题

我们可以枚举罪犯是谁,今天是星期几,从而判断每个人说的话是真是假

若每个人说的话的真假一致,且说谎话的人数<=k且说真话的人数<=m-k,就是一个符合的方案

而此题的精髓在于字符串的处理!

要知道每句话的末尾会有一个空格(为此爆到30分)

以及以下坑点:https://www.luogu.org/discuss/show/27320

CENGJINGYOUYIDUANZHENZHIDEGANQINGFANGZAIWOMIANQIANWOMEIYOUZHENXIDENGDAOSHIQULEYIHOUCAIZHUIHUIMOJIRENSHIJIANZUITONGKUDESHIMOGUOYUCIRUGUOSHANGTIANNENGGEIWOYIGEZAILAIYICIDEJIHUIWOHUIDUINAGENVHAIZISHUOSANGEZI:NIMABI !!!

具体看代码吧

#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
using namespace std;
#define N 25
int n,m,p,cnt,ans;
map<string,int> M;
struct ZC{
int pos,type,to;
//type 0:罪犯 1:不是罪犯 2:to是罪犯 3:to不是罪犯 4:today是to
} a[N];
string s[N],s1,s2,s3,s4,d1,d2,d3,d4,d5,d6,d7;
int h[N];
int main()
{
s1=" I am guilty.";
s2=" I am not guilty.";
s3=" is guilty.";
s4=" is not guilty.";
d1=" Today is Monday.";
d2=" Today is Tuesday.";
d3=" Today is Wednesday.";
d4=" Today is Thursday.";
d5=" Today is Friday.";
d5=" Today is Saturday.";
d7=" Today is Sunday.";
string x;
scanf("%d%d%d",&m,&n,&p);
getline(cin,x);
for(int i=;i<=m;i++){
cin>>s[i];
M[s[i]]=i;
}
while(p--){
cin>>x;
x.erase(x.end()-);
if(!M[x]){
getline(cin,x);
continue;
}
a[++cnt].pos=M[x];
getline(cin,x);
int it=x.find('.',);
x.erase(it+,x.length()-);
if(x==s1) a[cnt].type=;
else if(x==s2){ a[cnt].type=; }
else if(x==d1){ a[cnt].type=; a[cnt].to=; }
else if(x==d2){ a[cnt].type=; a[cnt].to=; }
else if(x==d3){ a[cnt].type=; a[cnt].to=; }
else if(x==d4){ a[cnt].type=; a[cnt].to=; }
else if(x==d5){ a[cnt].type=; a[cnt].to=; }
else if(x==d6){ a[cnt].type=; a[cnt].to=; }
else if(x==d7){ a[cnt].type=; a[cnt].to=; }
else{
x.erase(,);
int it=x.find(' ',);
string y=x.substr(,it);
x.erase(,it);
if(!M[y]){
cnt--;
continue;
}
a[cnt].to=M[y];
if(x==s3) a[cnt].type=;
else if(x==s4) a[cnt].type=;
else cnt--;
}
}
for(int gu=;gu<=m;gu++){
bool Flag=;
for(int day=;day<=;day++){
memset(h,,sizeof(h));
bool flag=; int tot1=,tot2=;
for(int i=;i<=cnt;i++){
int k;
switch(a[i].type){
case :{
if(a[i].pos==gu) k=;
else k=;
break;
}
case :{
if(a[i].pos!=gu) k=;
else k=;
break;
}
case :{
if(a[i].to==gu) k=;
else k=;
break;
}
case :{
if(a[i].to!=gu) k=;
else k=;
break;
}
case :{
if(a[i].to==day) k=;
else k=;
break;
}
}
if(!h[a[i].pos])
h[a[i].pos]=k;
else if(h[a[i].pos]!=k) flag=;
if(!flag) break;
}
if(!flag) continue;
for(int i=;i<=m;i++)
if(h[i]==) tot1++;
else if(h[i]==) tot2++;
if(tot2<=n&&n<=m-tot1){
Flag=; break;
}
}
if(Flag){
if(ans){
puts("Cannot Determine");
return ;
}
else ans=gu;
}
}
if(ans) cout<<s[ans]<<endl;
else puts("Impossible");
return ;
}
/*
附几个样例
3 1 5
MIKE
CHARLES
KATE
MIKE: I am guilty.
MIKE: Today is Sunday.
CHARLES: MIKE is guilty.
KATE: I am guilty.
KATE: How are you?? 2 2 4
HELLO
GUILTY
HELLO: What is your name?
GUILTY: I am GUILTY.
GUILTY: Are you guilty?
HELLO: I am not guilty. 5 1 5
A
B
C
D
E
A: Today is Monday.
B: Today is Thursday.
C: Today is Monday.
B: D is not guilty.
E: I am not guilty. */
05-17 03:33