Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

程序在这里

Posted by ykstars at 2005-05-30 08:44:42 on Problem 1058
In Reply To:这个题大家怎么过的??我的老是WA,能不能给一些数据啊 ,我试过一些是对的,程序如下: Posted by:ykstars at 2005-05-30 08:42:57
AFKP BELO CHIN DGJM
AEIM BFJN CGKO DHLP
ABCD EFGH IJKL MNOP
AGLN BHKM CEJP DFIO
AHJO BGIP CFLM DEKN
这是我的数据 可以得出结果
 #include <string>
#include <iostream>
#include <iomanip>
using namespace std;
int d[16][16];
int back(int k,int b[][16],int flag,int t,int rank)
{
	int m;
    
	
	int flag1=flag,flag3=0;
	int c[16][16];
	int p,q;
	int temp[16][16];
    int temp1[16][16]; 
	if(t>=15)return 0;
	
	
    for(p=0;p<16;p++)for(q=0;q<16;q++)
	{
		temp[p][q]=b[p][q];
		temp1[p][q]=b[p][q];
	}
    if(temp[k][k]==rank&&flag1==0)
	{
		if(k==15)
		{   
			if(rank==5)
			{
				for(p=0;p<16;p++)for(q=0;q<16;q++)d[p][q]=temp[p][q]; 
				
				
				return 1;
			}
			else 
			{
				for(q=0;q<16;q++)temp1[q][q]=0;
				return (back(0,temp1,0,0,rank+1));
			}
		}
		
		else 
		{   
			for(p=0;p<16;p++)for(q=0;q<16;q++)c[p][q]=temp[p][q];
			flag3=back(k+1,c,0,0,rank);
			if(flag3==1)
			{
				
				return 1;
				
			}
			else return 0;
			
		}
	}
	else
	{
		for(m=t+1;m<16;m++)
		{    
			if(m==k)continue;
			
			else if(temp[k][m]==0)
			{
				
				if(temp[m][m]==rank)continue;
				
				else
				{
					
					for(p=0;p<16;p++)
						for(q=0;q<16;q++)c[p][q]=temp[p][q];
						
						for(p=0;p<m;p++)
						{
							if(p==k)continue;
							else 	if(temp[k][p]==rank)
							{
								if(temp[p][m]!=0)break;
							}
						}
						if(p<m)continue;
						flag1++;
						temp[k][m]=rank;
						temp[m][k]=rank;
						temp[m][m]=rank;
						temp[k][k]=rank;
						for(p=0;p<m;p++)if(temp[k][p]==rank)
						{
							temp[p][m]=rank;
							temp[m][p]=rank;
						}
						
						if(flag1==3)
						{   
							if(k==15)
							{   
								if(rank==5)
								{
									for(p=0;p<16;p++)for(q=0;q<16;q++)d[p][q]=temp[p][q]; 
									
									return 1;
								}
								else 
								{  
									for(p=0;p<16;p++)for(q=0;q<16;q++)c[p][q]=temp[p][q];
									for(q=0;q<16;q++)c[p][p]=0;
									return (back(0,c,0,0,rank +1));
								}
								
							}
							
							flag3=back(k+1,temp,0,0,rank);
							if(flag3==0)
							{
								return (back(k,c,flag1-1,m,rank));
							}
							else 
							{  
								
								
								return 1;
								
							}
							
						}
						else
						{   
							
							flag3=back(k,temp,flag1,m,rank);
							if(flag3==0)
							{   
								
								return (back(k,c,flag1-1,m,rank));
							}
							else
							{
								
                                return 1;
								
							}
							
							
						}
				}
			}
		}
		if(m>=16)return 0;
	}
}

void main()
{
	int i,j;
	int a[16][16],b[16][16];
	string str1[5];
	char hh[4];
	int gg,kk;
	char c1,c2;
	int rank;
	int num=0;
	string s;
	int flag1;
	int pp;
	string str2[7];
	string stemp;
	int anum;
	string tt[16]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"};
	while(cin>>str1[0])
	{
		for(i=0;i<3;i++)
		{
			cin>>s;
			str1[0]=str1[0]+" ";
            str1[0]=str1[0]+s;
		}
		for(i=1;i<3;i++)
			for(str1[i]="",j=0;j<4;j++)
			{
				cin>>s;
				if(j>0)str1[i]=str1[i]+" ";
				str1[i]=str1[i]+s;
			}
			num++;
			
			
			for(i=0;i<16;i++)
				for(j=0;j<16;j++)a[i][j]=0;
				for(i=0;i<3;i++)
					for(gg=0,c1=c2=' ',j=0;j<16+3;j++)
					{
						c1=str1[i].at(j);
						
						if(c1==' '){ gg=0,c2=' ';continue;}
						hh[gg]=c1;
						gg++;
						for(kk=0;kk<gg;kk++)
						{
							a[c1-'A'][hh[kk]-'A']=i+1;
							a[hh[kk]-'A'][c1-'A']=i+1;
						}
					}
				for(i=0;i<16;i++)for(b[i][i]=0,j=0;j<16;j++)b[i][j]=a[i][j];
				for(i=0;i<16;i++)b[i][i]=0;
				flag1=back(0,b,0,0,4);
				if(flag1==1)
				{
					for(i=0;i<16;i++)for(j=0;j<16;j++)
					{    
						if(i==j)continue;
						if(d[i][j]==0)d[i][j]=5;
					}
						
					for(rank=1;rank<6;rank++)
					{  
					    str2[rank]="";
						for(pp=0;pp<16;pp++)d[pp][pp]=rank;
							
						for(i=0;i<16;i++)
							if(d[i][i]!=-1)
							{   
								if(i==0)str2[rank]=str2[rank]+"A";
								else str2[rank]=str2[rank]+" "+tt[i];
								d[i][i]=-1;
								for(j=0;j<16;j++)
								{   
									if(i==j)continue;
									if(d[i][j]==rank)
									{
										str2[rank]=str2[rank]+tt[j];
										d[i][j]=-1;
										d[j][i]=-1;
										d[j][j]=-1;
										
									}
									
									
								}
							}
								
					}
					for(i=1;i<6;i++)cout<<str2[i]<<endl;
				}
	            else cout<<"It is not possible to complete this schedule."<<endl;
	}
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator