[POJ 1386] Play on Words】的更多相关文章

Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11838   Accepted: 4048 Description Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because ther…
题目链接:http://poj.org/problem?id=1386 Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us.…
题目链接:http://poj.org/problem?id=1386 思路分析:该问题要求判断单词是否能连接成一条直线,转换为图论问题:将单词的首字母和尾字母看做一个点,每个单词描述了一条从首字母指向尾字母的有向边, 则则所有的单词构成了一个有向图,问题变为判断该有向图中是否存在一条欧拉路:有向图中存在欧拉路的两个充分必要条件为:该图是联通的并且所有的点的入度等于出度或者只存在两个点的入度与出度不等,一个点的入度=出度+1,另一个点的入度=出度-1: 代码如下: #include <cstdi…
题目链接:http://poj.org/problem?id=1386 题目大意:给你若干个字符串,一个单词的尾部和一个单词的头部相同那么这两个单词就可以相连,判断给出的n个单词是否能够一个接着一个全部连通. 解题思路:其实就是让你判断是否是欧拉回路或欧拉通路,建图需要一点思维,把26个字母当成是节点,每个单词当成是一条有向边. 这题自己先实现了一遍,发现虽然样例能过,但是有些情况没有考虑到,然后看了一下别人的代码,发现大部分人都是用并查集来做的,很巧妙的做法. #include <cstdio…
http://poj.org/problem?id=1386 题意: 给出多个单词,只有单词首字母与上一个单子的末尾字母相同时可以连接,判断所有字母是否可以全部连接在一起. 思路: 判断是否存在欧拉道路,每个单词只需要处理首字母和尾字母就可以了. 还有需要注意的就是需要判断图是否连通,我在这里用了并查集来判断. 有向图D存在欧拉道路的充要条件是:D为有向图,D的基图连通,并且所有顶点的出度与入度都相等:或者除两个顶点外,其余顶点的出度与入度都相等,而这两个顶点中一个顶点的出度与入度之差为1,另一…
题目链接:http://poj.org/problem?id=1386 题目大意:给你若干个字符串,一个单词的尾部和一个单词的头部相同那么这两个单词就可以相连,判断给出的n个单词是否能够一个接着一个全部连通. 解题思路:其实就是让你判断是否是欧拉回路或欧拉通路,建图需要一点思维,把26个字母当成是节点,每个单词当成是一条有向边.比如单词possible就是一条p->e的有向边. 代码: #include<iostream> #include<cstdio> #include&…
[题目链接] http://poj.org/problem?id=1386 [算法] 将每个单词的首字母向尾字母连一条有向边,判断欧拉路径是否存在,即可 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #…
题目链接: http://poj.org/problem?id=1386 Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9685   Accepted: 3344 Description Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve…
Play on Words Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us. There is a large numbe…
/* 题意:单词拼接,前一个单词的末尾字母和后一个单词的开头字母相同 思路:将一个单词的开头和末尾单词分别做两个点并建一条有向边!然后判断是否存在欧拉回路或者欧拉路 再次强调有向图欧拉路或欧拉回路的判定方法: (1)有向图G为欧拉图(存在欧拉回路),当且仅当G的基图连通,且所有顶点的入度等于出度. (2)有向图G为半欧拉图(存在欧拉道路),当且仅当G的基图连通,且存在顶点u的入度比出度大1.v的入度比出度小1, 其它所有顶点的入度等于出度(顶点u,v的个数必须都是1). 求该图的连通性的时候,只…
题目链接 题意 : 有很多门,每个门上有很多磁盘,每个盘上一个单词,必须重新排列磁盘使得每个单词的第一个字母与前一个单词的最后一个字母相同.给你一组单词问能不能排成上述形式. 思路 :把每个单词看成有首字母指向尾字母的有向边,每个字母看成一个点,题中要求等效于判断图中是否存在一条路径经过每一条一次且仅一次,就是有向欧拉通路.统计个顶点的出入度,如果每个点的出入度都相同,那就是欧拉回路,如果有两个奇数度,那就是欧拉通路,除此之外,都不能满足要求.还有别忘了判断是否连通,此时用到并查集,图中所有的边…
题意:给你一些字符串,这些字符串可以首位相接(末位置如果和另一个字符串的首位置相同的话就可以相连) .然后问你是否可以全部连起来. 思路:就是取出每个字符串的首尾位置,然后求出出度和入度,根据有向欧拉通路的性质,可以求出是否可以组成欧拉通路 . 当然还得考虑一下这个图是否是连通图,这里可以用并查集记录边的集合.最后判断是否是一个连通图. 欧拉通路水题. #include <iostream> #include <cstdio> #include <cstring> #i…
//本来是想练一下欧拉回路的,结果紫书上那题是大水题!!!!! 题意:给出n个单词,是否可以把单词排列成每个单词的第一个字母和上一个单词的最后一个字母相同 解:欧拉通路存在=底图联通+初度!=入度的点至多只有两个(分别为入点和出点) #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<cstring> #include<cstdli…
Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8768   Accepted: 3065 Description Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there…
Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11312   Accepted: 3862 Description Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because ther…
题目大意: 给一堆字母,让它们进行接龙,要头对尾能够接的上,问有没有一种方法让所有成语都完成接龙 这道题实际上是在考虑是否存在一条欧拉通路,每个单词产生一条有向线段,由第一个字母指向最后一个字母 这道题另一个需要考虑的是是否所有存在的字母都是处于一个连通分量中的,这里我们考虑用并查集来解决问题. 代码如下: #include <iostream> #include <cstdio> #include <cstring> using namespace std; ],],…
题意  见下方中文翻译 每一个单词能够看成首尾两个字母相连的一条边  然后就是输入m条边  推断是否能构成有向欧拉通路了 有向图存在欧拉通路的充要条件: 1. 有向图的基图连通: 2. 全部点的出度和入度相等  或者  仅仅有两个入度和出度不相等的点  且这两点入度与出度的差一个为-1(起点)一个为1(终点). 推断是否连通就是应用并查集了 #include<cstdio> #include<cstring> using namespace std; const int N = 3…
题意:要开启一扇门,n个单词是密码,n个单词中,如果一个单词的首字母和前一个单词的尾字母相同,并且每个单词都能这么连起来且只用一次,则门可以开启,否则不能开启,现给出单词,判断门是否可以开. 有向图欧拉通路充要条件:D为有向图,D的基图连通,并且所有顶点的出度与入度都相等:或者除两个顶点外,其余顶点的出度与入度都相等,而这两个顶点中一个顶点的出度与入度之差为1,另一个顶点的出度与入度之差为-1. 有向图欧拉回路充要条件:当D的所有顶点的出.入度都相等时,D中存在有向欧拉回路. 思路:一个单词关键…
题意:       给你n个单词,问你有没有一种排列方式可以所有单词的首部是相邻单词的尾部. 思路:       这个题目还挺基础的,就是个欧拉的判定,首先对于每一个单词,我们把他抽象成边,每个单词两端的字母抽象成边的两个点,这样就是判断有向图是否可以组成欧拉回路或者欧拉路径了,如果能那么就能达到题目要求,如果不能就不行,还有一点就是在判定欧拉的时候记得先并查集一遍,防止图不连通. 提示下:在连通图下,有向图欧拉回路的判定是所有点的入度等于出度.               在连通图下,有向图欧…
欧拉路: 如果给定无孤立结点图G,若存在一条路,经过图中每边一次且仅一次,这条路称为欧拉路: 如果给定无孤立结点图G,若存在一条回路,经过图中每边一次且仅一次,那么该回路称为欧拉回路. 存在欧拉回路的图,称为欧拉图. 一. 对于无向图G,具有一条欧拉路,当且仅当G是连通的,且有零个或两个奇数度结点. 且有零个奇数度结点,存在欧拉回路:有两个奇数度结点,存在欧拉路. 判断无向图G是否连通,可以从任意结点出发,进行深度优先遍历,如果可以遍历到所有点,也可以用并查集,判断根节点的个数, 说明,图G连通…
http://poj.org/problem?id=1176 Party Lamps Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4023   Accepted: 1386 Description To brighten up the gala dinner of the IOI'98 we have a set of N coloured lamps numbered from 1 to N. The lamps a…
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286   Accepted: 8603   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yumm…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 Description Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital le…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Accepted: 9197 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names t…