30pt,求调,悬关
查看原帖
30pt,求调,悬关
252401
xxx听取AC声一片楼主2023/9/18 14:27
#include<bits/stdc++.h>
using namespace std;
int M,N,P;
string name[25];
string Day[15]={"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
struct zy
{
	int lx;//1:我是罪犯 2:我不是罪犯 3:XXX是罪犯 4:XXX不是罪犯 5:今天是星期几 6:废话
	string sayer;//发言人
	string jg;//信息 
}a[105];
string happy="";
void fz(string s,int num)
{
	int k=s.find(':');
	string man=s.substr(0,k);
	string say=s.substr(k+2);
	a[num].sayer=man;
	if(say=="I am guilty.")
	{
		a[num].lx=1;	
		return ;
	}
	if(say=="I am not guilty.")
	{
		a[num].lx=2;
		return ;
	}
	int k2=say.find(' ');
	string men2=say.substr(0,k2),say2=say.substr(k2+1);
	bool can=false;
	for(int i=1;i<=M;i++)
		if(men2==name[i]) can=true;
	if(can)
	{
		if(say2=="is guilty.")
		{
			a[num].lx=3;
			a[num].jg=men2;
			return ;
		}
		else
		{
			if(say2=="is not guilty.")
			{
				a[num].lx=4;
				a[num].jg=men2;
				return ;
			}
			else 
			{
				a[num].lx=6;
				return ;
			}
		}
	}
	else
	{
		if(men2=="Today")
		{
			if(say2[0]=='i' && say2[1]=='s')
			{
				string day2=say2.substr(3);
				bool can=false;
				day2.replace(day2.size()-1,1,"");
				//cout<<day2<<'\n';
				for(int i=1;i<=7;i++)
					if(day2==Day[i]) can=true;
				if(can) 
				{
					a[num].lx=5;
					a[num].jg=day2;
					return ;
				}
				else
				{
					a[num].lx=6;
					return ;
				}
			}
			else
			{
				a[num].lx=6;
				return ;
			}
		}
		else
		{
			a[num].lx=6;
			return ;
		}
	}
}
string s[105];
map<string,bool> qwq,qwq2;
map<string,bool> fhdw;
int main()
{
	scanf("%d%d%d",&M,&N,&P);
	for(int i=1;i<=M;i++)
		cin>>name[i]; 
	for(int i=1;i<=P+1;i++)
	{
		getline(cin,s[i]);
		string s;
		while(s[s.size()-1]=='\r'|| s[s.size()-1]=='\n')
    		s.replace(s.size()-1,1,"");
	}			
	for(int i=2;i<=P+1;i++)
		fz(s[i],i-1);
	for(int i=1;i<=P;i++)
	{
		//cout<<a[i].sayer<<' '<<a[i].lx<<' '<<a[i].jg<<'\n';
		if(a[i].lx!=6) fhdw[a[i].sayer]=true;
	}
	int fh=0;
	for(int i=1;i<=M;i++)
		if(!fhdw[name[i]]) fh++; 
	//cout<<fh<<'\n';
	for(int week=1;week<=7;week++)
	{
		for(int killer=1;killer<=M;killer++)
		{
			int ans=0;
			for(int i=1;i<=M;i++)
				qwq[name[i]]=false;
			for(int i=1;i<=P;i++)
			{
				if(a[i].lx==6) continue;
				if(a[i].lx==1 && a[i].sayer!=name[killer]) 
				{
					if(!qwq[a[i].sayer]) ans++;
					qwq[a[i].sayer]=true;
				}
				if(a[i].lx==2 && a[i].sayer==name[killer]) 
				{
					if(!qwq[a[i].sayer]) ans++;
					qwq[a[i].sayer]=true;
				}
				if(a[i].lx==3) 
				{
					if(qwq[a[i].sayer])
					{
						if(a[i].jg==name[killer]) ans=0x3f3f3f3f;
						continue;
					}
					else
					{
						if(a[i].jg!=name[killer]) 
						{
							qwq[a[i].sayer]=true;
							ans++;
						}
					}
				}
				if(a[i].lx==4) 
				{
					if(qwq[a[i].sayer])
					{
						if(a[i].jg!=name[killer]) ans=0x3f3f3f3f;
						continue;
					}
					else
					{
						if(a[i].jg==name[killer]) 
						{
							qwq[a[i].sayer]=true;
							ans++;
						}
					}
				}
				if(a[i].lx==5) 
				{
					if(qwq[a[i].sayer])
					{
						if(a[i].jg==Day[week]) ans=0x3f3f3f3f;
						continue;
					}
					else
					{
						if(a[i].jg!=Day[week])
						{
							qwq[a[i].sayer]=true;	
							ans++;
						}
					}
				}
			}
			if(ans==N || (ans<N && N-ans<=fh)) 
			{
			//	cout<<Day[week]<<'\n';
			//	for(int i=1;i<=M;i++)
			//		if(qwq[name[i]]==true) cout<<name[i]<<' ';
			//	cout<<endl<<name[killer]<<'\n';
			//	cout<<ans<<'\n';
				bool can2=true;
				for(int k=1;k<=P;k++)
				{
					if(qwq[a[k].sayer])
					{
						if(a[k].lx==1 && a[k].sayer==name[killer]) can2=false; 
						if(a[k].lx==2 && a[k].sayer!=name[killer]) can2=false; 
						if(a[k].lx==3 && a[k].jg==name[killer]) can2=false; 
						if(a[k].lx==4 && a[k].jg!=name[killer]) can2=false; 
						if(a[k].lx==5 && a[k].jg==Day[week]) can2=false; 
					}
				}
				if(can2)
				{
					if(happy!="" && happy!=name[killer]) 
					{
						printf("Cannot Determine");
						return 0;
					}
					else happy=name[killer];	
				}
			}
		}
	}
	if(happy=="") printf("Impossible");
	else cout<<happy;
	return 0;
} 
2023/9/18 14:27
加载中...