Codeforces Round #288 (Div. 2) D Tanya and Password
来源:互联网 发布:网络兼职插画师 编辑:程序博客网 时间:2024/06/07 11:00
裸欧拉路,至于对欧拉路不了解的同学可以看本博客里对欧拉路的解释。
对于abc这个字符串,把ab、bc分别看成一个点连接一条边,然后直接欧拉路即可。
下面是AC代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<vector>using namespace std;vector<int >g[10005];int vis[100005];int in[10005],out[10005],use[10005];char c[6];int a[200005],cnt;int change(char c){ if(c>='a'&&c<='z') return c-'a'; if(c>='A'&&c<='Z') return 26+c-'A'; return 52+c-'0';}void add(int a,int b){ g[a].push_back(b);}int e,flag;int it[10005];void dfs(int u,int ee){ int p; p=(int)g[u].size(); while(it[u]<p){ int m=it[u]; it[u]++; use[g[u][m]]=1; dfs(g[u][m],0); } a[cnt++]=u;}int c2(int x){ if(x>=0&&x<=25) return x+'a'; if(x>=26&&x<=51){ return x-26+'A'; } return x-52+'0';}int c1(int p){ int x; x=p/100; return c2(x);}int main(){ int i,n,m; int aa,b,p; cin>>n; for(i=0;i<n;i++){ scanf("%s",c); aa=change(c[0]); b=change(c[1]); p=change(c[2]); add(aa*100+b,b*100+p); in[b*100+p]++; out[aa*100+b]++; e+=2; } int x=0,y=0; m=0; for(i=0;i<=10000;i++){ if(in[i]!=out[i]){ if(in[i]==out[i]+1){ x++; } else if(out[i]==in[i]+1){ y++; } else{ m=1; } } } if(!((x==0&&y==0)||(x==1&&y==1))) m=1; if(m) printf("NO\n"); else{ if(x==0){ for(i=0;i<=10000;i++){ if(in[i]!=0){ use[i]=1; dfs(i,0); break; } } } else{ for(i=0;i<=10000;i++){ if(out[i]==in[i]+1){ use[i]=1; dfs(i,0); break; } } } for(i=0;i<=10000;i++){ if(!(in[i]==0&&out[i]==0)){ if(!use[i]){ m=1; break; } } } if(m) printf("NO\n"); else{ printf("YES\n"); printf("%c",c2(a[cnt-1]/100)); for(i=cnt-1;i>=0;i--){ printf("%c",c2(a[i]%100)); } } }}
0 0
- Codeforces Round #288 (Div. 2)---D. Tanya and Password
- Codeforces Round #288 (Div. 2) D. Tanya and Password
- Codeforces Round #288 (Div. 2) D Tanya and Password
- Codeforces Round #288 (Div. 2)---D. Tanya and Password
- CodeForces 508D(Codeforces Round #288 (Div. 2))Tanya and Password
- Codeforces Round #288 (Div. 2) D.Tanya and Password(欧拉路径)
- Codeforces Round #288 (Div. 2)D.Tanya and Password——欧拉通路
- Codeforces Round #288 (Div. 2) D. Tanya and Password (欧拉通路)
- Codeforces Round #288 (Div. 2) D. Tanya and Password 欧拉回路
- Codeforces Round #288 (Div. 2)-D. Tanya and Password(欧拉路径及其打印)
- codeforces Round#288D Tanya and Password 欧拉通路
- 【欧拉回路】 Codeforces 288 D Tanya and Password
- Codeforces 508D Tanya and Password
- Codeforces 508D Tanya and Password
- Codeforces Round #293 (Div. 2) -- B. Tanya and Postcard
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya
- Hibernate之五 HQL&QBC
- 2015-3-23:(1)getopt函数
- ACM--steps--dyx--1.3.2--今年暑假不AC
- java输入输出流
- 解决 multiple definition of
- Codeforces Round #288 (Div. 2) D Tanya and Password
- iOS开发系列--通知与消息机制
- DriverManager.registerDriver(new Driver())不能执行的原因
- 深入理解计算机系统 1.3 理解编译系统如何工作是有回报的
- mysql客户端Navicat_Premium_11.0.17_XiaZaiBa.exe导出excel文件
- spring mvc架构分析
- 不要学习代码,要学会思考
- 呵呵,类
- uva 10740 Not the Best 两点之间的K短路径