http://codeforces.com/contest/508/problem/D

以上是题目链接

题目大意 给n个字符串看能不能链接在一起

因为 三个三个分割 所以字符串  如abc ab作为起点 bc作为终点

hash思想 加细节处理 欧拉图均满足

#include<cstdio>
#include<map>
//#include<bits/stdc++.h>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
#include<cstdlib>
#include<climits>
#include<cctype>
#define PI acos(-1.0)
#define INF 0x3fffffff
using namespace std;
typedef long long ll;
typedef __int64 int64;
const ll mood=1e9+;
const int64 Mod=;
const double eps=1e-;
const int N=8e3;
const int MAXN=;
typedef int rl;
inline void r(rl&num){
num=;rl f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<='')num=num*+ch-'',ch=getchar();
num*=f;
}
int gt(char a)//hash
{
if(isdigit(a)) return a-'';
if(islower(a)) return a-'a'+;
return a-'A'+;
}
int ha(char a,char b)
{
return gt(a)*+gt(b);
}
char fg(int a)
{
if(a<)return a+'';
if(a<=gt('z')) return a-+'a';
return a-+'A';
}
vector<int>v[N];
string ss;
void dfs(int x)
{
while(!v[x].empty()){
int tem=v[x].back();
v[x].pop_back();
dfs(tem);
}
ss+=fg(x%);
//cout<<ss<<endl;
}
int ind[N];
int main()
{
char ch[];
int n;
r(n);
for(int i=;i<n;i++)
{
scanf("%s",ch);
int s=ha(ch[],ch[]),e=ha(ch[],ch[]);
v[s].push_back(e);
ind[s]++;ind[e]--;
}
int st=-,out=;//-1表示回路
for(int i=;i<N;i++)
{
if(ind[i]>=){
st=i;
out++;
}
}
if(out>||ind[st]>)//ind[s] 表示图仅有一个点指向多个点构成
{
puts("NO");
return ;
}
if(st==-)
{
for(int i=;i<N;i++)
{
if(!v[i].empty())
{
st=i;
break;
}
}
}
dfs(st);
ss+=fg(st/);
if(ss.size()==n+)
{
puts("YES");
for(int i=n+;i>=;i--)
cout<<ss[i];
}
else{
puts("NO");
}
return ;
}

欧拉

欧拉回路/通路 Codeforces Round #288 (Div. 2)的更多相关文章

  1. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  2. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  3. Codeforces Round #288 (Div. 2)D. Tanya and Password 欧拉通路

    D. Tanya and Password Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/508 ...

  4. Codeforces Round #288 (Div. 2) E. Arthur and Brackets

    题目链接:http://codeforces.com/contest/508/problem/E 输入一个n,表示有这么多对括号,然后有n行,每行输入一个区间,第i行的区间表示从前往后第i对括号的左括 ...

  5. Codeforces Round #288 (Div. 2)

    A. Pasha and Pixels     题意就是给一个n*m的矩阵,k次操作,一开始矩阵全白,一次操作可以染黑一个格子,问第几次操作可以使得矩阵中存在一个2*2的黑色矩阵.直接模拟即可 代码: ...

  6. 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels

    题目传送门 /* 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 很挫的判断四个方向是否OK */ #include <cs ...

  7. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #288 (Div. 2) E. Arthur and Brackets 贪心

    E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input stand ...

  9. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. c语言中的# ## 可变参数宏 ...和_ _VA_ARGS_ _

    1.#假如希望在字符串中包含宏参数,ANSI C允许这样作,在类函数宏的替换部分,#符号用作一个预处理运算符,它可以把语言符号转化程字符串.例如,如果x是一个宏参量,那么#x可以把参数名转化成相应的字 ...

  2. Makefile研究(二)—— 完整可移植性模板

    转自:http://blog.csdn.net/jundic/article/details/17676461 一直想写一个很全很好移植的Makefile模板,我觉得一个完整makefile 应该包含 ...

  3. C#基础:通过委托给任何对象数组进行排序

    在日常编写程序的时候,我们需要对一些对象进行排序,比如对int数组进行排序,自定义类数组进行排序,首先我们先讨论对数组进行排序,我们应该对冒泡排序比较熟悉,下面是数组用冒泡排序的方法 for (int ...

  4. E20180615-hm

    fraction  n. [数] 分数; 一小部分,些微; 不相连的一块,片段; [化] 分馏; infinity n. <数>无穷大; 无限的时间或空间; product n. 产品; ...

  5. Mac和Unix的常用命令行指令

    更新:2017/05/03/02:05 更新: 2017/05/14/11:14 更新: 2017/09/05/16:15 增加rm -rf 强制删除文件夹内所有文件 更新: 2018/01/16 完 ...

  6. Legacy C++ MongoDB Driver

    https://docs.mongodb.com/ecosystem/drivers/cpp/

  7. ACM心理过程

    ACM 都已经一个学期过去了,然后还是很菜很菜,比起别人真的是差到一种境界好么???因为自身的太多原因,因为学的不够精,因为懒惰,因为学习的方法,因为自身对未来的不渴望.因为自满,因为自己的自甘堕落, ...

  8. MyBatis中的RowBounds

    myBatis中实现分页的方式是采用RowBounds这个类,用法如下,xml语句不变 传入两个参数,strat起始行, limit是当前页显示多少条数据,原理是RowBounds在处理分页时,只是简 ...

  9. [Xcode 实际操作]二、视图与手势-(7)UIView视图的渐变填充

    目录:[Swift]Xcode实际操作 本文将演示创建一个具有渐变填充色的图形 import UIKit class ViewController: UIViewController { overri ...

  10. 阿里巴巴开源性能监控神器Arthas初体验

    如果问性能测试中最难的是哪部分,相信很多人会说“性能调优”.确实是这样,性能调优是一个非常复杂.技术含量很高的工作.涉及到的知识面很广.以我多年从业经验来看,在企业里,大多数的性能调优都是由开发架构师 ...