usaco Riding the Fences
2011-10-11 12:33
435 查看
这道题目很意思,呵呵……
代码好下:
代码好下:
/* ID: guo geer PROG: fence LANG: C++ */ #include<iostream> #include<cstring> #include<cmath> #include<fstream> using namespace std; int a[510][510],b[510],path[1029],stack[1029]; int getMin(int s[]) { for(int i=1; i<=500; i++) if(s[i] > 0) return i; return -1; } int main() { ifstream fin("fence.in"); ofstream fout("fence.out"); int F; while(fin>>F) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); int x,y,st=510; for(int i=0; i<F; i++) { fin>>x>>y; st=min(st,min(x,y)); a[x][y] ++; a[y][x] ++; b[x] ++; b[y] ++; } for(int i=1; i<=500; i++) if(b[i]%2 == 1){st = i; break;} int p = 0, top=-1; stack[++ top] = st; while(top != -1) { st = stack[top]; if(b[st] == 0) path[p ++] = st, top --; while(b[st] > 0) { int tt = getMin(a[st]); b[st] --; b[tt] --; a[st][tt] --; a[tt][st] --; st = tt; stack[++top] = st; } } for(int i=F; i>=0; i--) fout<<path[i]<<endl; } return 0; }
相关文章推荐
- USACO Riding The Fences (点最小字典序欧拉路径 Fleury)
- usaco Riding the Fences(欧拉回路模板)
- USACO Riding the fences and C implement
- USACO3.3.1--Riding the Fences
- usaco Riding the Fences
- usaco 3.3 Riding the Fences
- usaco 3.2 Riding The Fences
- USACO Riding the Fences 解题报告
- USACO 3.3 Riding The Fences
- USACO - Riding the Fences (Fleury算法找欧拉路径/欧拉回路模板)
- USACO / Riding the Fences (欧拉路径)
- 欧拉路径, 欧拉回路 USACO Riding the Fences
- USACO-Section 3.3-PROB Riding The Fences
- USACO: Chap3 Riding the Fences
- 欧拉回路 USACO 3.3.1 Riding the Fences
- [USACO3.3.1]Riding the Fences
- C++&Pascal——【USACO 3.3.1】——Riding the Fences
- Riding the Fences
- usaco3.3Riding the Fences输出欧拉通路
- 【题解】Luogu 骑马修栅栏 Riding the Fences (欧拉回路+搜索)