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 |
大佬求解释!为什么我的代码会RE……#include<iostream> #include<vector> #include<cstring> #include<stack> #include<queue> #include<map> #include<set> #include<algorithm> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define MAXN 30 #define INF 999999 int V,E; bool G[MAXN][MAXN]; //vector<int> edge[MAXN]; int in[MAXN]; int out[MAXN]; bool vis[MAXN]; int MIN,MAX,n; void dfs_lt(int v){ n++; vis[v]=true; for(int i=0;i<MAXN;i++){ if(G[v][i]==true&&vis[i]==false){ dfs_lt(i); } } } int main(){ ios::sync_with_stdio(false); int T; cin >> T; while(T--){ cin >> V; mem(G,false); mem(in,0); mem(out,0); mem(vis,false); n=0; char str[1005]; MAX=-INF;MIN=INF; for(int i=0;i<V;i++){ cin >> str; int len=strlen(str); int a = str[0]-'a'; int b = str[len-1]-'a'; // cout << *str.begin() << " " << str.at(str.size()-1) << endl; // cout << a << " " << b << endl; MIN = min(MIN,min(a,b)); MAX = max(MAX,max(a,b)); G[a][b]=true; //edge[a].push_back(b); in[b]++; out[a]++; } vis[MIN]=true; // cout << MIN << endl; dfs_lt(MIN); V=0; for(int i=0;i<MAXN;i++) if(in[i]!=0||out[i]!=0) V++; // cout << V << endl; if(n==V){ int cnt=0; int xx[5]; for(int i=0;i<MAXN;i++) if(in[i]!=out[i]) xx[cnt++]=i; if(cnt==2) if((in[xx[0]]-1==out[xx[0]]&&in[xx[1]]+1==out[xx[1]])||(in[xx[0]]==out[xx[0]]-1&&in[xx[1]]==out[xx[1]]+1)) cout << "Ordering is possible.\n"; else cout << "The door cannot be opened.\n"; else if(cnt==0) cout << "Ordering is possible.\n"; else cout << "The door cannot be opened.\n"; }else cout << "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