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 |
哪一位大哥给我看看啊,有空请你们吃饭啊,,怎么验证对一提交就错啊,麻烦了,牛人们!帮帮我吧,不胜感激#include<iostream> #include<string.h> #include<stdio.h> using namespace std; #define MAX 1001 char r[100001]; int out[MAX],in[MAX],p[MAX],exist[MAX],mark[MAX]; void build() { int i; for(i=1;i<=26;i++) p[i]=i; } int find(int x) { if(x!=p[x]) p[x]=find(p[x]); return p[x]; } void merge(int x,int y) { int n,m; n=find(x); m=find(y); p[n]=m; } int main() { int f,i,j,n,m,len,s,ans; scanf("%d",&n); while(n--) { memset(out,0,sizeof(out)); memset(in,0,sizeof(in)); memset(exist,0,sizeof(exist)); memset(mark,0,sizeof(mark)); scanf("%d",&m); build(); for(i=1;i<=m;i++) { scanf("%s",r); len=strlen(r); out[r[0]-96]++; in[r[len-1]-96]++; mark[r[0]-96]=1; mark[r[len-1]-96]=1; merge(r[0]-96,r[len-1]-96); } ans=0; for(i=1;i<=26;i++) { s=find(i); if(exist[s]==0&&p[i]!=i) { exist[s]=1; ans++; } } if(ans!=1) printf("The door cannot be opened.\n"); else { int z,q; z=0;q=0; ans=0; for(j=1;j<=26;j++) if(mark[j]!=0) { ans++; if(out[j]==in[j]) continue; else if(in[j]==out[j]+1) z++; else if(out[j]==in[j]+1) q++; else break; } if(j>26&&((q==0&&z==0)||(z==1&&q==1))) printf("Ordering is possible.\n"); else printf("The door cannot be opened.\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator