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 |
For Help,WA 2337I think that I am right, but I WAed #include<iostream> #include<string> #define maxn 26 using namespace std; string line[maxn][maxn]; int pos,store[maxn]; int n,_count,_tot; int degree[2][maxn],st; int adj[maxn][maxn]; bool check(){ int a,b,c; a=b=0; for (int i=0;i<maxn;++i){ if (degree[0][i]-degree[1][i]==1){ ++a; st=i; } else if (degree[0][i]-degree[1][i]==-1) ++b; else if (degree[0][i]==degree[1][i]) ++c; else return false; } if (a==1&&b==1) return true; if (a==0&&b==0) return true; return false; } bool fluery(int dep,int v){ bool tmp; if (dep==n) return true; for (int i=0;i<=25;++i) if (adj[v][i]){ --adj[v][i]; store[pos++]=i; if (fluery(dep+1,i)) return true; ++adj[v][i]; --pos; } return false; } void output(){ int p=1; cout<<line[store[0]][store[1]]; for (int i=1;i<n;++i){ cout<<"."<<line[store[p]][store[p+1]]; ++p; } cout<<endl; } void work(){ string s; cin>>n; for (int i=0;i<n;++i){ cin>>s; line[s[0]-'a'][s[s.size()-1]-'a']=s; ++adj[s[0]-'a'][s[s.size()-1]-'a']; ++degree[0][s[0]-'a']; ++degree[1][s[s.size()-1]-'a']; } if (check()){ store[0]=st; pos=1; fluery(0,st); output(); } else cout<<"***"<<endl; } int main (void){ int t; cin>>t; while (t){ work(); --t; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator