悬赏10元解答,样例和测试点1本地运行没问题,但洛谷上全RE完全想不明白
查看原帖
悬赏10元解答,样例和测试点1本地运行没问题,但洛谷上全RE完全想不明白
1533737
null___楼主2024/11/10 17:45
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int a[1000]={0,0,0},v[1000]={0,0,0},n,y=0;
int b[2000][200];
int xuanren(int k,int m)
{
	int x,z,t=1,p,q=0;
	if(k>n)
	{
				for(p=1;p<=y;p++)
				{
				  for(z=1;z<=m;z++)
				  {
					for(x=1;x<=m;x++)
					{
					   if(a[z]==b[p][x])break;
				    }
				    if(x<m+1)q++;
			      }
			      if(q==m)
			      {
			      	t=0;break;
				  }
				}
		if(t)
		{
			y++;
			for(x=1;x<=m;x++)
			{
				b[y][x]=a[x];
			}
		}
	}
	else
	{
		int i;
		for(i=1;i<=n;i++)
		{
			if(v[i]==0)
			{
				v[i]=1;
				a[k]=i;
				xuanren(k+1,m);
				a[k]=0;
				v[i]=0;
			}
		}
	}
}

int main()
{
	int fake,talk;
	scanf("%d%d%d",&n,&fake,&talk);
	getchar();
	int p,q,h,c[2000]={0,0,0},d[2000]={0,0,0,0},e,f,u=0,w,g,j,l,o;
	char str1[50]="I am guilty.";
    char str2[50]="I am not guilty.";
    char str3[50]="is guilty.";
    char str4[50]="is not guilty.";
    char name[2000][2000],s[2000][2000],s1[2000][2000],s2[2000][2000];
    char s3[2000][2000],s4[2000][2000];
	xuanren(1,fake);
    for(p=1;p<=n;p++)
    {
    	scanf("%s",name[p]);
	}
	getchar();
	 for(p=1;p<=talk;p++)
    {
    	for(q=0;q<=199;q++)
    	{
    		char temp;
    		temp=getchar();
    		if(temp=='\n')break;
    		else s[p][q]=temp;
		}
	}
	//getchar();
	for(p=1;p<=talk;p++)
	{
		for(q=0;;q++)
		{
			if(s[p][q]==':')break; 
			s1[p][q]=s[p][q];
		}
	}
	for(p=1;p<=talk;p++)
	{
		for(q=2,h=0;q<=strlen(s[p])-1;)
		{
			if(s[p][q-2]==':'&&s[p][q-1]==' ')
			{
				for(;q<=strlen(s[p])-1;q++)
				{
				s2[p][h]=s[p][q];
				h++;
			    }
			    break;
			} 
			else q++;
		}
	}
	for(p=1;p<=talk;p++)
	{
		for(q=2,h=0,w=0;q<=strlen(s[p])-1;)
		{
			if(s[p][q-2]==':'&&s[p][q-1]==' ')
			{
				for(;q<=strlen(s[p])-1;q++)
				{
				  if(s[p][q]!=' ')
				 {
				   s3[p][h]=s[p][q];
				   h++;
			     }
			      else
			      {
			      	q++;break;
				  }
			    }
			    for(;q<=strlen(s[p])-1;q++,w++)
			    {
			    	s4[p][w]=s[p][q];
				}
				break;
			}
			else q++; 
		}
	}
	for(q=1;q<=y;q++)
	{
		u=0;
		for(g=1;g<=n;g++)
		{
			c[g]=2;
		}
		f=0;
		for(h=1;h<=talk;h++)
		{
			for(p=1;p<=n;p++)
			{
				if(strcmp(s1[h],name[p])==0)break;
			}
			for(e=1;b[y][e]!=0;e++)
			{
				if(p==b[y][e])
				{
					f=1;
				}
			}
			if(f)
			{
				if(strcmp(str1,s2[h])==0)
				{
					if(c[p]==1)
					{
						u=1;
						break;
					}
					c[p]=0;
				}
				else if(strcmp(str2,s2[h])==0)
				{
					if(c[p]==0)
					{
						u=1;
						break;
					}
					c[p]=1;
				}
				else
				{
					for(w=1;w<=n;w++)
					{
						if(strcmp(s3[h],name[w])==0)break; 
					}
					if(w==n+1)continue;
					if(strcmp(s4[h],str3)==0)
					{
						if(c[w]==1)
					  {
						u=1;
						break;
					  }
					   c[w]=0;
					}
					else if(strcmp(str4,s4[h])==0)
				    {
					   if(c[w]==0)
					  {
						u=1;
						break;
					  }
					   c[w]=1;
				    }
					
				}
			}
			else
			{
				if(strcmp(str1,s2[h])==0)
				{
					if(c[p]==0)
					{
						u=1;
						break;
					}
					c[p]=1;
				}
				else if(strcmp(str2,s2[h])==0)
				{
					if(c[p]==1)
					{
						u=1;
						break;
					}
					c[p]=0;
				}
				else
				{
					for(w=1;w<=n;w++)
					{
						if(strcmp(s3[h],name[w])==0)break; 
					}
					if(w==n+1)continue;
					if(strcmp(s4[h],str3)==0)
					{
						if(c[w]==0)
					  {
						u=1;
						break;
					  }
					   c[w]=1;
					}
					else if(strcmp(str4,s4[h])==0)
				    {
					   if(c[w]==1)
					  {
						u=1;
						break;
					  }
					   c[w]=0;
				    }
				}
			}
		}
		if(u)continue;
		for(g=1,j=0;g<=n;g++)
		{
			if(c[g]==1)
			{
				j++;
				l=g;
			}
		}
		if(j==1)d[l]=1;
	}
	for(o=0,g=1;g<=n;g++)
	{
		if(d[g]==1)
		{
			o++;
			l=o;
		}
	}
	int i;
	for(i=1;i<=y;i++)
	{
		for(j=1;;j++)
		{
			if(b[i][j]!=0)
			printf("%d ",b[i][j]);
			else break;
		}
		putchar('\n');
	}
	if(o==0)printf("Impossible");
	if(o==1)printf("%s",name[l]);
	if(o>1)printf("Cannot Determine");
	return 0;
}

2024/11/10 17:45
加载中...