[POJ 1041] John's Trip
[题目链接]
http://poj.org/problem?id=1041
[算法]
欧拉回路
[代码]
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 2010
#define MAXM 45 int i,u,v,cnt,max_id,id;
int degree[MAXN],ans[MAXN];
bool visited[MAXN];
pair<int,int> e[MAXN];
bool flag; inline void dfs(int u)
{
int i,v;
for (i = ; i <= max_id; i++)
{
if (!visited[i] && (e[i].first == u || e[i].second == u))
{
visited[i] = true;
dfs(e[i].first + e[i].second - u);
ans[++cnt] = i;
}
}
} int main()
{ while (scanf("%d%d",&u,&v) != EOF)
{
if (!u && !v) break;
max_id = ;
memset(degree,false,sizeof(degree));
memset(visited,false,sizeof(visited));
scanf("%d",&id);
max_id = max(max_id,id);
e[id] = make_pair(u,v);
degree[u]++; degree[v]++;
while (scanf("%d%d",&u,&v) && (u || v))
{
scanf("%d",&id);
e[id] = make_pair(u,v);
max_id = max(max_id,id);
degree[u]++; degree[v]++;
}
flag = false;
for (i = ; i <= ; i++)
{
if (degree[i] & )
{
flag = true;
break;
}
}
if (flag)
{
printf("Round trip does not exist.\n");
continue;
}
cnt = ;
dfs();
for (i = cnt; i >= ; i--) printf("%d ",ans[i]);
printf("\n");
} return ; }
[POJ 1041] John's Trip的更多相关文章
- poj 1041 John's trip——欧拉回路字典序输出
题目:http://poj.org/problem?id=1041 明明是欧拉回路字典序输出的模板. 优先队列存边有毒.写跪.学习学习TJ发现只要按边权从大到小排序连边就能正常用邻接表了! 还有一种存 ...
- poj 1041 John's trip 欧拉回路
题目链接 求给出的图是否存在欧拉回路并输出路径, 从1这个点开始, 输出时按边的升序输出. 将每个点的边排序一下就可以. #include <iostream> #include < ...
- POJ 1041 John's trip 无向图的【欧拉回路】路径输出
欧拉回路第一题TVT 本题的一个小技巧在于: [建立一个存放点与边关系的邻接矩阵] 1.先判断是否存在欧拉路径 无向图: 欧拉回路:连通 + 所有定点的度为偶数 欧拉路径:连通 + 除源点和终点外都为 ...
- POJ 1041 John's trip Euler欧拉回路判定和求回路
就是欧拉判定,判定之后就能够使用DFS求欧拉回路了.图论内容. 这里使用邻接矩阵会快非常多速度. 这类题目都是十分困难的.光是定义的记录的数组变量就会是一大堆. #include <cstdio ...
- UVA302 John's trip(欧拉回路)
UVA302 John's trip 欧拉回路 attention: 如果有多组解,按字典序输出. 起点为每组数据所给的第一条边的编号较小的路口 每次输出完额外换一行 保证连通性 每次输入数据结束后, ...
- poj 1041(字典序输出欧拉回路)
John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8641 Accepted: 2893 Spe ...
- POJ1041 John's trip
John's trip Language:Default John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- Java实现John's trip(约翰的小汽车)
1 问题描述 John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8998 Accepted: 3018 Sp ...
- John's trip POJ - 1041(这题数据有点水)
题意: 其实还是一个欧拉回路,但要按字典序走路: 解析: 我真是蠢啊emm... map[i][j]表示由顶点i经街道j会到达的顶点编号 然后枚举j就好了 用栈储存.. 虽然我不是这样写的 #incl ...
随机推荐
- Tcl之Lab1
Task 1. Use help 1) What is the default switch for the redirect command? -file help -v redirect # or ...
- mysql幻读
开启a,b两个数据库连接,a.b都开启事务后,b插入了一条数据R并提交,验证对a的操作造成的影响 select select for update update R update R 后 select ...
- 您厉害您赚得多:聪明投资者的聊天记录,雪球CEO的21条投资理念
3星|<您厉害您赚得多>:雪球创始人的投资理念.原则.技巧,及其在雪球上跟一些用户的互动的内容 作者是雪球创始人.CEO,全书基本是作者的一些投资理念+作者在雪球上跟用户的互动的内容,还有 ...
- C 语言常用方法技巧
C语言常用方法技巧 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !impor ...
- Centos6.6 安装基于系统认证的vsftp服务
一.介绍 vsftp是一款文件服务器软件,在文件共享,代码更新,文件备份中也是经常用到,以下是基本安装环境: 1)CentOS6.6 2)vsftpd-2.2.2 二.安装 $ yum install ...
- (转) 分布式文件存储FastDFS(一)初识FastDFS
http://blog.csdn.net/xingjiarong/article/details/50559849 一.FastDFS简介 FastDFS是一款开源的.分布式文件系统(Distribu ...
- c#仿照qq登录界面编辑框内容操作
using System; using System.Drawing; using System.Windows.Forms; namespace 案例演示 { public partial clas ...
- 常见的CPU指令集介绍
本文摘自网络 一.X86 是微处理器执行的计算机语言指令集,指一个intel通用计算机系列的标准编号缩写,也标识一套通用的计算机指令集合,属于CISC. 1.1.简介 X86指令集是美国Intel ...
- 在Excel表格中打字为何会被覆盖掉
修改证件图片背景:https://www.cnblogs.com/liyanbin/p/9466746.html Insert键是插入和改写(覆盖)的开关如果当前处于改写(覆盖)模式,再按一下Inse ...
- [转载]java中Date,SimpleDateFormat
一.Java中的日期概述: 日期在Java中是一块非常复杂的内容,对于一个日期在不同的语言国别环境中,日期的国际化,日期和时间之间的转换,日期的加减运算,日期的展示格式都是非常复杂的问题. 在Java ...