【图论】[luoguP2731]骑马修栅栏 Riding the Fences
来源:互联网 发布:淘宝买家让加微信骗局 编辑:程序博客网 时间:2024/05/16 18:31
题目
半年前刚学图论的时候就做过 今天竟然忘了 翻书才想起来欧拉路。。
也就是一笔画问题 深搜就可以了
代码如下
#include<iostream>#include<cstdio>#include<cctype> using namespace std; #define in = read(); typedef long long ll; typedef unsigned int ui; const ll size = 1500 + 10; int f , x , y; int map[size][size]; int start = 1 , minn , maxx , len; int ans[size] , du[size];inline ll read(){ ll num = 0 , f = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)){ num = num*10 + ch - '0'; ch = getchar(); } return num*f;}void dfs(int i){ for(register int j=minn;j<=maxx;j++) if(map[i][j]){ map[i][j] --; map[j][i] --; dfs(j); } ans[++ len] = i;}int main(){ f in; for(register int i=1;i<=f;i++){ x in; y in; map[x][y] ++; map[y][x] ++; du[x] ++; du[y] ++; minn = min(min(x , minn) , y); maxx = max(max(x , maxx) , y); } for(register int i=minn;i<=maxx;i++) if(du[i]%2 == 1){ start = i; break; } dfs(start); for(register int i=len;i>=1;i--) printf("%d\n" , ans[i]);}//COYG
阅读全文
0 0
- 【图论】[luoguP2731]骑马修栅栏 Riding the Fences
- [LUOGU2731] 骑马修栅栏 Riding the Fences
- 【USACO题库】3.3.1 Riding the Fences骑马修栅栏
- 洛谷 P2731 骑马修栅栏 Riding the Fences
- [USACO3.3]骑马修栅栏 Riding the Fences
- LUOGU P2731 骑马修栅栏 Riding the Fences
- luoguP2731 骑马修栅栏 题解
- USACOTraining 3.3.1 Riding the Fences 骑马修栅栏 题解
- 【题解】Luogu 骑马修栅栏 Riding the Fences (欧拉回路+搜索)
- JZOJ1288.【USACO题库】3.3.1 Riding the Fences骑马修栅栏
- 洛谷 2731 骑马修栅栏 Riding the Fences 欧拉路径
- usaco Riding the Fences
- Riding the Fences
- Riding the Fences
- 深搜解Riding the Fences
- USACO: Chap3 Riding the Fences
- usaco 3.2 Riding The Fences
- usaco 3.3 Riding the Fences
- SpringMVC日期类型转换问题三大处理方法归纳
- 运维之思科篇 -----5. NAT及静态转换 、 动态转换及PAT
- JVM(7):JVM调优-工具篇
- Storm
- MySQL架构设计——MyISAM存储引擎与InnoDB存储引擎
- 【图论】[luoguP2731]骑马修栅栏 Riding the Fences
- windows命令行下:telnet访问163邮箱服务器和qq邮箱服务器发送邮件
- C语言中const关键字详解
- Android 5.0以下出现 java.lang.NoClassDefFoundError:
- Myeclipse提高效率的生僻快捷键
- 图像处理--形态学
- 十年建站老司机带你十分钟搭建网站
- Linux redis 配置文件
- 【UVA1335】Beijing Guards