Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
所有的测试数据都通过了,为什么还wa呢?#include<iostream> using namespace std; int n,m,i,j,w; int t[26][26]; char c[26]; int num,num1,num2; bool d=true; void check(int a) { for(int k=0;k<26;k++) { for(i=0;i<26;i++) for(j=1;j<26;j++) { if(t[i][k]==-1&&t[k][j]==-1) { t[i][j]=-1; t[j][i]=1; } } } for(i=0;i<26;i++) { num1=0,num2=0; for(j=0;j<26;j++) { if(t[i][j]==1) { num1++; num++; } else if(t[i][j]==-1) num2++; } if(num1!=0||(num1==0&&num2!=0)) c[num1]=i+65; } if(num>=n*(n-1)/2) //要确定他们之间的关系 { d=true; cout<<"Sorted sequence determined after "<<a+1<<" relations: "; for(i=0;i<n;i++) cout<<c[i]; cout<<"."<<endl; } } int main() { freopen("in.txt","r",stdin); char a,b,p; char aa[1000],bb[1000]; while(cin>>n>>m&&n!=0&&m!=0) { d=false; memset(t,0,sizeof(t)); for(w=0;w<m;w++) cin>>aa[w]>>p>>bb[w]; for(w=0;w<m;w++) { a=aa[w]; b=bb[w]; if(a==b) { cout<<"Inconsistency found after "<<w+1<<" relations."<<endl; //发现矛盾 break; } num=0; if( t[a-65][b-65]==0|| t[a-65][b-65]==-1) { t[a-65][b-65]=-1; t[b-65][a-65]=1; } else //未确定顺序发现矛盾,如果已确定顺序就算了 { cout<<"Inconsistency found after "<<w+1<<" relations."<<endl; //发现矛盾 break; } check(w); //判断是可以确定 if(d==true) break; } if(w==m&&d==false) //如果未确定关系且所有输入关系已做过判断 cout<<"Sorted sequence cannot be determined."<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator