关于P1039 [NOIP2003 提高组] 侦探推理
查看原帖
关于P1039 [NOIP2003 提高组] 侦探推理
550740
wanhongwu楼主2023/8/14 23:31

样例也过不了,求调

#include<bits/stdc++.h>
using namespace std;
int n,m,t;
map<string,int> seg;
string rev[25];
string con[105];
string week[8]={"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int ans;
int cnt;
int est;
int Judge(int i,int j,int k){
	string s=con[k];
	int x=s.find(':');
	string name=s.substr(0,x);
	s=s.substr(x+1,s.size()-x);
	s=s+" ";
	x=s.find(' ');
	if(s=="I am guilty."){
		if(seg[name]==j) return 1;
		else return 0;
	}else if(s=="I am not guilty."){
		if(seg[name]==j) return 0;
		else return 1;
	}else if(seg[s]!=0){
		name=s.substr(0,x);
		s=s.substr(x+1,s.size()-x);
		if(s=="is guilty."){
			if(seg[name]==j) return 1;
			else return 0;
		}else{
			if(seg[name]==j) return 0;
			else return 1; 
		}
	}else if(s.substr(0,x)=="Today"){
		if(s==("Today is "+week[i]+".")) return 1;
		else return 0;
	}else{
		return 0x3f3f3f3f; 
	}
}
int main(){
	cin>>n>>m>>t;
	for(int i=1;i<=n;i++){
		cin>>rev[i];
		seg[rev[i]]=i;
	}
	getchar();
	for(int i=1;i<=t;i++){
		getline(cin,con[i]);
	}
	for(int i=1;i<=7;i++){
		for(int j=1;j<=n;j++){
			est=0;
			for(int k=1;k<=t;k++){
				est+=Judge(i,j,k);
			}
			if(n-est==m){
				cnt++;
				ans=i;
			}
		}
	}
	if(cnt==0) cout<<"Impossible";
	else if(cnt>1) cout<<"Cannot Determine";
	else cout<<rev[ans];
	return 0;
}
2023/8/14 23:31
加载中...