USACO Riding Fences 欧拉回路
来源:互联网 发布:种子填充算法例子 编辑:程序博客网 时间:2024/06/04 18:08
参考: http://www.cppblog.com/Ylemzy/articles/100050.html
注意path数组长度为1025(edge的个数),刚开始弄成501(vertex个数)结果test 8 爆栈了
/* ID: wangxin12 PROG: fence LANG: C++ */#include <iostream>#include <fstream>#define MAX 505#define Max(a,b) (a > b ? a : b)#define Min(a,b) (a < b ? a : b)using namespace std;int map[MAX][MAX], num[MAX], path[1050]; //map¹¹Í¼£¬ num¼ÇÔØÿ¸öµã¶ÈÊý£¬path¼ÇÔØ·¾¶int minn, maxn, index = 0; //ÒòΪÌâÄ¿ÖÐvertex²»´Ó1¿ªÊ¼£¬ÒªÔÚ¶ÁÈëÊý¾ÝµÄʱºò¼ÇÔØvertexµÄ×îС×î´óÖµvoid circle(int x) {int i;if(num[x]) {do {for(i = minn; i <= maxn; i++) {if(map[x][i]) break; } //find the smallest neighbormap[x][i]--, map[i][x]--;num[x]--, num[i]--; //delete this edgecircle(i); //} while ( num[x] );path[index++] = x;}else path[index++] = x;}void deal() {int i;for(i = minn; i <= maxn; i++) {if(num[i] % 2 == 1) {circle(i);return;}}circle(minn);}int main() {ifstream fi("fence.in");ofstream fo("fence.out");//intputint n, from, to, i;fi>>n;for(i = 1, minn = 500, maxn = 1; i <= n; i++) {fi>>from>>to;map[from][to]++, map[to][from]++;num[from]++, num[to]++;if( minn > Min(from, to) ) minn = Min(from, to);if( maxn < Max(from, to) ) maxn = Max(from, to);}deal();//outputfor(int j = index - 1; j >= 0; j--) {fo<<path[j]<<endl;}fi.close();fo.close();return 0;}
- USACO Riding Fences 欧拉回路
- 欧拉路径, 欧拉回路 USACO Riding the Fences
- USACO Section 3.3 Riding The Fences - 欧拉回路
- 欧拉回路 USACO 3.3.1 Riding the Fences
- USACO-Section 3.3 Riding the Fences(欧拉回路)
- usaco Riding the Fences(欧拉回路模板)
- USACO Riding The Fences 与欧拉路径问题
- Riding the Fences (USACO 3.3) 无向图欧拉通路/回路
- 【题解】Luogu 骑马修栅栏 Riding the Fences (欧拉回路+搜索)
- usaco Riding the Fences
- USACO section 3.3 Riding the Fences(欧拉通路的遍历,dfs)
- USACO 3.3.1Riding the Fences(弗罗莱算法寻找欧拉通路)
- USACO: Chap3 Riding the Fences
- usaco 3.2 Riding The Fences
- usaco 3.3 Riding the Fences
- usaco java Riding the Fences
- usaco 3.3 Riding the Fences
- usaco3.3Riding the Fences输出欧拉通路
- php 获取日期(当天,前天,明天,本周,本月,本季度,本年)
- PHP写文本日志
- android如何与服务端通信
- 引入rmxftmpl.h头文件报错
- 给xcode 的颜色选择其添加16进制颜色选择器
- USACO Riding Fences 欧拉回路
- 改icon图标
- VS2008 自用注释宏
- c c++ 中的文件路径表示
- C#生成code128条形码
- Distributional hypothesis
- 关注生活,创新自然
- load_elf_binary中使用的内存映射机制
- nginx 301 跳转