UVa 10129 Play on Words 欧拉通路
来源:互联网 发布:java 垃圾评论过滤 编辑:程序博客网 时间:2024/06/05 18:24
注意到给出的所有点可能不连通,所以要用并查集
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<climits>#include<queue>#include<vector>#include<map>#include<sstream>#include<set>#include<stack>#include<utility>#pragma comment(linker, "/STACK:102400000,102400000")#define PI 3.1415926535897932384626#define eps 1e-10#define sqr(x) ((x)*(x))#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)#define lson num<<1,le,mid#define rson num<<1|1,mid+1,ri#define MID int mid=(le+ri)>>1#define zero(x)((x>0? x:-x)<1e-15)using namespace std;const int INF =0x3f3f3f3f;const int maxn= 100000+20 ;//const int maxm= ;//const int INF= ;typedef long long ll;const ll inf =1000000000000000;//1e15;//ifstream fin("input.txt");//ofstream fout("output.txt");//fin.close();//fout.close();//freopen("a.in","r",stdin);//freopen("a.out","w",stdout);char s[1010];int in[maxn];int out[maxn];int pre[30];vector <int>spe;int id(char x){ return x-'a';}int find(int x){ return x==pre[x]?x:pre[x]=find(pre[x]);}void merge(int u ,int v){ int x=find(u); int y=find(v); if(x!=y) pre[u]=v;}void init(){ for(int i=0;i<26;i++) pre[i]=i;}int main(){ int T,n; scanf("%d",&T); while(T--) { spe.clear(); init(); for(int i=0;i<26;i++) { in[i]=out[i]=0; } scanf("%d",&n); while(n--) { scanf("%s",s); int len=strlen(s); int st=id(s[0]); int ed=id(s[len-1]); merge( st,ed ); out[st]++; in[ed]++; } for(int i=0;i<26;i++) { if(out[i]!=in[i]) spe.push_back(i); } int prin; for(int i=0;i<26;i++) { if(in[i]!=0||out[i]!=0) {prin=find(i);break;} } bool ok=1; for(int i=0;i<26;i++) { if( (in[i]!=0||out[i]!=0 )&&find(i)!=prin ) { ok=0; break; } } if(!ok) { puts("The door cannot be opened.");continue;} if(spe.size()==0) {puts("Ordering is possible.");continue;} else if(spe.size()==2) { int a=spe[0],b=spe[1]; if( in[a]-out[a]==1&&out[b]-in[b]==1||in[a]-out[a]==-1&&out[b]-in[b]==-1) {puts("Ordering is possible.");continue;} } puts("The door cannot be opened."); } return 0;}
0 0
- UVa 10129 Play on Words 欧拉通路
- UVa--10129 Play on Words(欧拉通路)
- 10129 - Play on Words//欧拉通路
- 欧拉通路-Play on Words
- Play on Words,UVA 10129——求欧拉回路/欧拉通路
- uva 10129 Play On Words(单词)求欧拉回路或欧拉通路
- poj 2016 Play on Words--欧拉通路
- hdu 1116 Play on Words(欧拉通路)
- POJ 1386 Play on Words(欧拉通路)
- HDU 1116 Play on Words(欧拉通路)
- poj 1386 Play on Words(欧拉通路)
- UVA10129:Play on Words(欧拉通路存在性)
- Play on Words UVa欧拉回路
- 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 (欧拉路径+dfs)
- 常见的一些eclipse开发常用的快捷键
- 360在线笔试题:求数列的和
- 欢迎使用CSDN-markdown编辑器
- android ratingbar自定义图片
- I学霸官方免费教程十七:Java面向对象之接口
- UVa 10129 Play on Words 欧拉通路
- [图论]最大流介绍 Ford-Fulkerson算法 邻接表实现
- 简单好记又完整的的配置环境变量
- getAttribute和getParameter区别
- 杭电 1513 Palindrome LCS DP
- (1)why我要学习PHP内核源码
- HDU5365Run(计算几何)详解
- Android studio两个便利的方法
- atitit. 分销系统规划p8k