10129 - Play on Words
来源:互联网 发布:大班美工 剪纸花瓣 编辑:程序博客网 时间:2024/05/16 10:43
单词是边,两端字母是节点,图有没有欧拉回路。判断图的连通性和各节点的度
要求。所有节点出入度为零或者只有两个节点,总和有一个出度和一个入度
#include <iostream>#include <string>#include <vector>#include <cstring>using namespace std;const int maxn = 30;int uset[26],used[26];int degree[maxn];void usetinit(){for(int i=0;i<26;i++)uset[i] = i;}int find_root(int x){return uset[x] == x?x:uset[x] = find_root(uset[x]);}int union_set(int x,int y){ uset[x] = y; }int main(){int t,n,a,b;string s;cin>>t;while(t--){cin>>n;memset(degree,0,sizeof(degree));memset(used,0,sizeof(used));usetinit();int cc = 26;for(int i=0;i<n;i++){cin>>s;a = s[0] - 'a'; b = s[s.size() - 1] - 'a';degree[a]--;degree[b]++;used[a]=used[b] = 1;int r1 = find_root(a);int r2 = find_root(b);if(r1 != r2){union_set(r1,r2);cc--;}}vector<int> ans;for(int i=0;i<26;i++){if(used[i] == 0)cc--;else if(degree[i] != 0)ans.push_back(degree[i]);}if(cc==1&&(ans.empty() || (ans.size() == 2 && (ans[0] == 1 || ans[0] == -1))))cout<<"Ordering is possible.\n";else cout<<"The door cannot be opened.\n";}system("pause");return 0;}
要求。所有节点出入度为零或者只有两个节点,总和有一个出度和一个入度
0 0
- 10129 - Play on Words
- 10129 Play on Words
- 10129 - Play on Words
- 10129 - Play on Words
- uva 10129 - Play on Words
- UVaOJ 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 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 10129 Play on Words
- uva 10129 - Play on Words
- UVA 10129 Play on Words
- link.exe 的参数
- 字符串
- Maven核心概念
- 用到了base64转图片文件的函数,记录一下
- 《史蒂夫·乔布斯传》(Steve Jobs)官方正式中文版高清PDF
- 10129 - Play on Words
- 1. Two Sum
- PHP5.2+fastcgi安装Zend Optimizer的安装方法
- jsoup api 用法
- zabbix安装部署
- 我有博客啦!
- Managing Audio Playback之Controlling Your App’s Volume and Playback
- IntelliJ IDEA生成注册码Java代码
- window.getComputedStyle() returns null inside an iframe with display: none