把26个小写字母当成点,每个单词就是一条边. 然后就是求欧拉路径. #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 1000000007 const int INF=0…
题目链接: https://vjudge.net/problem/ZOJ-1456 These are N cities in Spring country. Between each pair of cities there may be one transportation track or none. Now there is some cargo that should be delivered from one city to another. The transportation f…
题目链接:http://poj.org/problem?id=2337 题目大意:给你n个字符串,只有字符串首和尾相同才能连接起来.请你以最小字典序输出连接好的单词. 解题思路:跟POJ1386一个意思,就是把26个字母当成点,单词当做有向边,判断欧拉回(通)路.但是要输出路径也就是单词,而且要求字典序最小. 可以通过将单词先排序再添加边使字典序最小,还有注意起点,如果有一个出度比入度大1的点,就从这个点出发,否则从最小的点出发. 代码: #include<iostream> #include…
题目链接:http://poj.org/problem?id=1041 思路:懒得写了,直接copy吧:对于一个图可以从一个顶点沿着边走下去,每个边只走一次,所有的边都经过后回到原点的路.一个无向图存在欧拉回路的充要条件是每个顶点的度是偶数, 对于有向图存在欧拉回路的条件是每个顶点的出度等于入度(就是出去的边数等于进来的边数).根据这个首先判断存在欧拉回路不, 如果存在然后用DFS去找欧拉回路.DFS的思想等效于先找一个环,然后对环上所有点递归DFS,并且把这些递归产生的路插入这个环中. 实际上…
题意: 如果给出的单词能够首尾相接,请按字典序输出单词,中间要加'.' 否则输出三个"*". 思路: 欧拉回路 记得按字典序排序哦~ 加边的时候要倒着加.(邻接表遍历的时候是反着的) 记得清空vis数组(因为这个无脑错误WA了好长时间.....) 随便搞搞 就能过了. 数据不是很强- #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char…
Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10186   Accepted: 2650 Description A catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1814 Problem Description The Public Peace Commission should be legislated in Parliament of The Democratic Republic of Byteland according to The Very Important Law. Unfortunately one of the obstacles is t…
#include <iostream> #include <algorithm> #include <vector> #include <cstdio> #include <cstring> using namespace std; ; int a[N]; ]; vector < vector <); int n,m; bool cmp (vector<int> x, vector<int> y) {// 不用…
题意: 就是给出几个单词 看能否组成欧拉回路或路径  当然还是让输出组成的最小字典序的路 解析: 还是把首尾字母看成点   把单词看成边 记录边就好了 这题让我对fleury输出最小字典序又加深了一些认识 fleury输出最小字典序  就必须保证对应输出的边或点  按从小到大的顺序去走 所以我们先保存  然后排序  然后从大到小加边 因为我们用的是邻接表  邻接表是从当前起点u的最后一个加入的边 开始的 ..所以我们要对应起来 把边从大到小依次加入 #include <iostream> #i…
描述 It's your first day in Quality Control at Merry Milk Makers, and already there's been a catastrophe: a shipment of bad milk has been sent out. Unfortunately, you didn't discover this until the milk was already into your delivery system on its way…