uva 10129 poj 1386 hdu 1116 zoj 2016 play on words
//本来是想练一下欧拉回路的,结果紫书上那题是大水题!!!!!
题意:给出n个单词,是否可以把单词排列成每个单词的第一个字母和上一个单词的最后一个字母相同
解:欧拉通路存在=底图联通+初度!=入度的点至多只有两个(分别为入点和出点)
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string> using namespace std; int T,n;
int in[],out[];
int f[];
char s[]; int gf(int x){
if (x==f[x]) return f[x];
f[x]=gf(f[x]);
return f[x];
} bool solve(){
memset(in,,sizeof(in));
memset(out,,sizeof(out));
for (int i=;i<;i++){
f[i]=i;
}
scanf("%d",&n);
for (int i=;i<n;i++){
scanf("%s",s);
int f1=gf(s[]-'a');
int f2=gf(s[strlen(s)-]-'a');
if (f1!=f2){
f[f1]=f2;
}
in[s[]-'a']++;
out[s[strlen(s)-]-'a']++;
}
int pre=-;
for (int i=;i<;i++){
if (in[i]!= || out[i]!=){
if (pre==-)
pre=gf(i);
else{
if (pre!=gf(i)) return false;
pre=gf(i);
}
}
}
for (int i=;i<;i++){
in[i]=in[i]-out[i];
}
sort(in,in+);
for (int i=;i<;i++) if (in[i]!=) return false;
if (abs(in[])> || abs(in[])> || in[]+in[]!=) return false;
if (in[]+in[]!=) return false;
return true;
} int main(){
scanf("%d",&T);
for (int cas=;cas<=T;cas++){
if (solve())
printf("Ordering is possible.\n");
else
printf("The door cannot be opened.\n");
}
return ;
}
/*
3
2
acm
ibm
3
acm
malform
mouse
2
ok
ok
*/
uva 10129 poj 1386 hdu 1116 zoj 2016 play on words的更多相关文章
- POJ 1386&&HDU 1116 Play on Words(我以后再也不用cin啦!!!)
Play on Words Some of the secret doors contain a very interesting word puzzle. The team of archaeolo ...
- POJ 1564(HDU 1258 ZOJ 1711) Sum It Up(DFS)
题目链接:http://poj.org/problem?id=1564 题目大意:给定一个整数t,和n个元素组成的集合.求能否用该集合中的元素和表示该整数,如果可以输出所有可行解.1<=n< ...
- POJ 2062 HDU 1528 ZOJ 2223 Card Game Cheater
水题,感觉和田忌赛马差不多 #include<cstdio> #include<cstring> #include<cmath> #include<algor ...
- POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups / HDU 1699 Jamie's Contact Groups / SCU 1996 Jamie's Contact Groups (二分,二分图匹配)
POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups ...
- POJ 2104&HDU 2665 Kth number(主席树入门+离散化)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 50247 Accepted: 17101 Ca ...
- POJ 1386 Play on Words(欧拉图的判断)
Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11838 Accepted: 4048 De ...
- POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat 二分)
POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat ...
- poj 1251 poj 1258 hdu 1863 poj 1287 poj 2421 hdu 1233 最小生成树模板题
poj 1251 && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
随机推荐
- vs2012 发布网站丢失文件
问题描述 在发布网站时,发现上线的网站总是功能缺失,而本地代码确实没问题. 到发布网站的磁盘去查看,发现丢失了很多静态页面文件. 这是一个很奇怪的问题:mvc的网站,丢失了很多View(大部分的csh ...
- 轻松搞定javascript原型链 _proto_
//如有错误或不同观点,欢迎批评与讨论! 首先,prototype出现的目的,是为了解决 代码重用 的问题 , prototype 相当于是在内存上划分出一个公共的区域, 专用于存放 实例化对象 的相 ...
- jquery序列化元素
序列化元素: 做项目的时候,表单是必不可少的,经常用来提交数据,例如注册.登陆等.常规的方法是使表单提交到另外一个页面,整个浏览器都会被刷新,而使用Ajax技术则能够异步地提交表单,并将服务器返回的数 ...
- CmdParse
Procedure URPOSE Uses Dos,Crt; Const VersionNum = 'V1.0 BETA'; ProgNameStr = 'NEWPROJ.EXE'; ProgName ...
- linux arp攻击解决方法 测试很有效
公司有台centos服务器中了arp攻击,严重影响业务,测试了很多方法都没解决,机房技术也没法处理. 通过下面方法,可以有效抵挡arp攻击. 1.环境 centos6.4 2.执行 arpin ...
- OleVariant的本质
OleVariant的本质 OleVariant,COM的一种数据类型.MIDAS基于COM之上构建的,自然使用OleVariant作为数据序列格式. 延续到现在最新的DATASNAP仍然支持它. T ...
- IOS研究院之打开照相机与本地相册选择图片
如下图所示 在本地相册中选择一张图片后,我们将他拷贝至沙盒当中,在客户端中将它的缩略图放在按钮旁边,这个结构其实和新浪微薄中选择图片后的效果一样.最终点击发送将按钮将图片2进制图片上传服务器. 下面我 ...
- jQuery粘性跟随滚动条滚动的导航栏源代码下载
jQuery粘性跟随滚动条滚动的导航栏源代码下载 作者:网页模板 大小:0.005MB 点击次数:3494 发布时间:2014-03-07 12:55 分享到:0 特效介绍 jQuery粘性跟随滚动条 ...
- xrdp的rdp前端无法连接Windows 2008的问题
xrdp使用rdp前端,无法连接2008,但连接2003是可以的.连接2008的时候,会在客户端发送Client Info PDU后主动RST掉连接.如下图 开始以为是客户端发送Client Info ...
- matlab 矩阵
假设矩阵A=[1 3;4 2] 1.对角置零: A-diag(diag(A)) 2.求A的特征值以及特征向量: 用到eig(A)函数,此函数有五种用法,如下: 2.1 E=eig(A):求矩阵A的全部 ...