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 ...
随机推荐
- 转 jquery插件--241个jquery插件—jquery插件大全
241个jquery插件—jquery插件大全 jquery插件jqueryautocompleteajaxjavascriptcoldfusion jQuery由美国人John Resig创建,至今 ...
- 菜鸟的jQuery源码学习笔记(前言)
前言 相信任何一名前端开发人员或者是前端爱好者都对jQuery不陌生.jQuery简单易用,功能强大,特别是拥有良好的浏览器兼容性,大大降低了前端开发的难度,使得前端开发变得“平易近人起来”.自从本人 ...
- ACID:数据库事务正确执行的四个基本要素
ACID,指数据库事务正确执行的四个基本要素的缩写.包含:原子性(Atomicity).一致性(Consistency).隔离性(Isolation).持久性(Durability).一个支持事务(T ...
- Python 自带IDLE中调试程序
在vs2013下调试过Python,今天试了下使用自带IDLE调试,相比而言后者效果不好. 记录一下 http://q.cnblogs.com/q/35869/ 在“Python Shell”窗口中单 ...
- COMET技术具体实现 结合PHP和JQUERY
具体看代码,费话不说 PHP服务端 $mem = new RTMEM(); if(!$mem->conn()) exit('no mem server'); if(!$mem->getst ...
- 解决Eclipse下第三方库无法导航源代码
写在前面(的废话):Eclipse无法导航代码,存在的可能性非常多,这里我们只讨论在引用第三方库时无法导航的情况,是一个很简单的Case,但是搜索能力好像不太及格,没找到一针见血的方案,于是自己研究了 ...
- MySQL----alter table modify | change的不同
1.modify.change都可以修改列的属性:一同的是modify只能修改表的数据类型.change比它要牛逼一点它可以在修改数据类型的同时也修改列名. 2.modify 的语法:alter ta ...
- Oracle EBS-SQL (WIP-14):检查车间需求与BOM差异对照.sql
select a.*, b.BOM定额, a.WIP定额 - b.BOM定额 差异 from (select WE.WIP_ENTITY_NAME ...
- NOR和NAND flash区别,RAM 和ROM区别
ROM是Read Only Memory的缩写.RAM是Random Access Memory的缩写.典型的RAM就是计算机的内存. RAM有两大类,一种称为静态RAM(Static RAM/SRA ...
- 利用netstat和tasklist查看PC的端口占用情况
经常,我们在启动应用的时候发现系统需要的端口被别的程序占用,如何知道谁占有了我们需要的端口? 1.Windows平台在windows命令行窗口下执行: E:\oracle\ora92\bin>n ...