【poj1041】 John's trip
http://poj.org/problem?id=1041 (题目链接)
题意
给出一张无向图,求字典序最小欧拉回路。
Solution
这鬼畜的输入是什么心态啊mdzz,这里用vector储存边,便于边的排序。瞬间变成STL常数boy →_→。
细节
数组大小把握好。
代码
// poj1041
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#define LL long long
#define inf 2147483640
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; const int maxn=2000;
struct edge {
int to,id;
friend bool operator < (const edge a,const edge b) {
return a.id<b.id;
}
};
int vis[maxn],r[maxn],s[maxn],top,rt;
vector<edge> e[maxn]; void dfs(int x) {
for (int i=0;i<e[x].size();i++) if (!vis[e[x][i].id]) {
vis[e[x][i].id]=1;
dfs(e[x][i].to);
s[++top]=e[x][i].id;
}
}
int main() {
int x,y,z;
while (scanf("%d%d",&x,&y)!=EOF && x && y) {
memset(vis,0,sizeof(vis));
for (int i=1;i<maxn;i++) e[i].clear(),r[i]=0;
rt=min(x,y);
while (x && y) {
scanf("%d",&z);
e[x].push_back((edge){y,z});
e[y].push_back((edge){x,z});
r[x]++;r[y]++;
scanf("%d%d",&x,&y);
}
int flag=0;
for (int i=1;i<maxn;i++) if (r[i]&1) {flag=1;break;}
if (flag) {puts("Round trip does not exist.");continue;}
for (int i=1;i<maxn;i++) sort(e[i].begin(),e[i].end());
top=0;
dfs(rt);
while (top) printf("%d ",s[top--]);puts("");
}
return 0;
}
【poj1041】 John's trip的更多相关文章
- 【HDOJ】2425 Hiking Trip
优先级队列+BFS. #include <iostream> #include <cstdio> #include <cstring> #include <q ...
- 【BZOJ】【1022】【SHOI2008】小约翰的游戏John
博弈论 一看题,哇这不是Nim游戏么= =直接异或起来……啊咧怎么不对? 这道题是[Anti-Nim],普通的Nim是取走最后一个就赢,这题是取走最后一个输…… 做法参见 2009年贾志豪论文< ...
- 【POJ3683】Priest John's Busiest Day
题目 John is the only priest in his town. September 1st is the John's busiest day in a year because th ...
- 【bzoj1022】小约翰的游戏John
Portal -->bzoj1022 Solution 这题其实是裸的反Nim,这里主要是为了写反Nim游戏的证明 首先给出反Nim(anti-nim)的定义和结论: [定义]桌子上 ...
- 【BZOJ】1022: [SHOI2008]小约翰的游戏John(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=1022 好神的博弈论. 题解见dzy的blog:http://dzy493941464.is-prog ...
- POJ3683 Priest John's Busiest Day 【2-sat】
题目 John is the only priest in his town. September 1st is the John's busiest day in a year because th ...
- 【题解】POJ1934 Trip (DP+记录方案)
[题解]POJ1934 Trip (DP+记录方案) 题意: 传送门 刚开始我是这么设状态的(谁叫我DP没学好) \(dp(i,j)\)表示钦定选择\(i\)和\(j\)的LCS,然而你会发现这样钦定 ...
- POJ1041 John's trip
John's trip Language:Default John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- 【dp】codeforces C. Vladik and Memorable Trip
http://codeforces.com/contest/811/problem/C [题意] 给定一个自然数序列,在这个序列中找出几个不相交段,使得每个段的异或值之和相加最大. 段的异或值这样定义 ...
随机推荐
- 批量去除Teleport Pro整站下载文件冗余代码
teleport pro tppabs标签批量删除 teleport pro tppabs标签批量删除 使 用Teleport Pro下载的网页代码中包含了很多垃圾代码,比如下载的html网页代码中会 ...
- BZOJ 1087 【SCOI2005】 互不侵犯King
Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. Input 只有一行,包 ...
- Android 常用的adb命令
1.安装APK(如果加 -r 参数,保留已设定数据,重新安装filename.apk) adb install xxx.apk adb install -r xxx.apk 2.卸载APK(如果加 - ...
- TinyFrame升级之九:实现复杂的查询
本章我们主要讲解如何实现一个复杂的查询.由于目前TinyFrame框架已经投入到了实际的项目生产中,所以我很乐意将项目中遇到的任何问题做以记录并备忘. 这章中,我们提到的查询界面如下所示: 其中,涉及 ...
- python数字图像处理(16):霍夫圆和椭圆变换
在极坐标中,圆的表示方式为: x=x0+rcosθ y=y0+rsinθ 圆心为(x0,y0),r为半径,θ为旋转度数,值范围为0-359 如果给定圆心点和半径,则其它点是否在圆上,我们就能检测出来了 ...
- PhoneGap: Android平台入门例子(Hello World)
Hello World Demo: http://docs.phonegap.com/en/2.0.0/guide_getting-started_android_index.md.html#Gett ...
- latex中页面距离的设置
1.页面设置 a4 会给你一个较小的页面,为了使用更多的控制,可用 geometry宏包和命令 \layout . 2.改变长度 在latex里改变长度的命令是 \addtolength 和 \set ...
- 在stream流和byte[]中查找(搜索)指定字符串
在 stream流 和 byte[] 中查找(搜索)指定字符串 这里注重看的是两个 Search 的扩展方法,一个是 stream 类型的扩展,另一个是 byte[] 类型的扩展, 如果大家有更好的“ ...
- android 发送GET请求 服务端接收乱码的问题
在android的编程中常会使用get/post请求,在用get请求的时候数据是直接放在url当中的 例如: http://apicloud.mob.com/v1/weather/query?key= ...
- oracle递归查询树的SQL语句
来自互联网 SELECT * FROM a_ParkingLot AWHERE A.REGIONID IN( SELECT r.ID FROM a_region r START WITH ...