【例题 6-16 UVa 10129】Play on Words
2017-11-17 06:43
429 查看
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
入度减去出度个数为1的点和为-1的点各有1个,然后其他点入度减去出度为0
或者全都是入度为0的点即可。
【代码】
#include <bits/stdc++.h> using namespace std; const int N = 300; int n,du ; map <char,int> mmap; int f[N+10]; bool bo[N+10]; int ff(int x){ if (f[x]==x) return x; else return f[x] = ff(f[x]); } int main(){ #ifdef LOCAL_DEFINE freopen("F:\\c++source\\rush_in.txt", "r", stdin); #endif ios::sync_with_stdio(0),cin.tie(0); int T; cin >> T; while (T--){ memset(du,0,sizeof du); memset(bo,0,sizeof bo); for (int i = 'a';i <= 'z';i++) f[i] = i; cin >> n; string s; for (int i = 1;i <=n;i++){ cin >> s; int x = s[0],y = s[(int) s.size()-1]; du[(int) s[0]]++; du[(int) s[(int) s.size()-1]]--; bo[(int) s[0]] = true; bo[(int) s[(int) s.size()-1]] = true; if (ff(x)!=ff(y)){ f[ff(x)] = ff(y); } } bool ok = true; int idx = 'a'; for (int i = 'a';i <= 'z';i++) if (bo[i]){ idx = ff(i); } for (int i = 'a';i <= 'z';i++) if (bo[i]&& ff(i)!=idx) ok = false; if (!ok){ cout <<"The door cannot be opened."<<endl; continue; } int fi1 = 0,fi2 = 0; for (int i = 'a';i <= 'z';i++) if (du[i]==-1) fi1++; else if (du[i]==1){ fi2++; }else if (du[i]!=0) fi1 = 2; if ((fi1==1 && fi2==1) || (fi1==0 && fi2==0)){ cout << "Ordering is possible." << endl; }else cout <<"The door cannot be opened."<<endl; } return 0; }
相关文章推荐
- 例题6-16 UVA 10129 Play On Words单词
- 例题6-16 单词(Play On Words, UVa 10129)
- 【例题 6-15 UVA - 10129】Play on Words
- UVA - 10129 Play on Words
- 【欧拉路的判断 DFS判断连通】UVA - 10129 Play on Words
- Play on Words 单词 UVA 10129 (欧拉+dfs)
- uva 10129 play on words——yhx
- uva 10129 - Play on Words
- UVA-10129 Play on Words
- UVa 10129 - Play on Words(欧拉道路)
- UVA 10129-Play on Words(欧拉通路)
- UVa 10129 - Play on Words
- UVA - 10129Play on Words(欧拉路)
- uva 10129 Play on Words
- Uva10129 Play on Words【dfs解欧拉回路】【例题6-16】
- (欧拉回路)uva 10129 Play On Words
- UVa 10129 - Play on Words (欧拉回路, DFS)
- UVA - 10129 Play on Words
- UVA 10129 - Play on Words
- uva 10129 Play On Words(单词)求欧拉回路或欧拉通路