POJ 1041 欧拉回路
2016-07-12 22:02
411 查看
题意:
John要去访问他的朋友,在这个城市中有n条街道,每条街道与别的街道有两个交点,现在给出这些街道的信息(即输入x y z表示街道z的两个端点为x,y),问其是否可以每条街道只经过一次,如果存在,则输出字典序最小的路线,不存在则输出”Round trip does not exist.”
注意:
是边的字典序最小的路线。
思路:DFS+stack随便搞一搞就出来了
一开始脑残。。。用邻接表写。。。。。写了快半个小时 发现
woc?
然后怎么写。。。。。
就改成了邻接矩阵了。。
没想到和题解的思路竟然一样。
Code length竟然进了前5
我只想问 第一名怎么23B写完的!!!
John要去访问他的朋友,在这个城市中有n条街道,每条街道与别的街道有两个交点,现在给出这些街道的信息(即输入x y z表示街道z的两个端点为x,y),问其是否可以每条街道只经过一次,如果存在,则输出字典序最小的路线,不存在则输出”Round trip does not exist.”
注意:
是边的字典序最小的路线。
思路:DFS+stack随便搞一搞就出来了
一开始脑残。。。用邻接表写。。。。。写了快半个小时 发现
woc?
然后怎么写。。。。。
就改成了邻接矩阵了。。
没想到和题解的思路竟然一样。
// by SiriusRen #include <cstdio> #include <cstring> #include <algorithm> #define N 55 using namespace std; int xx,yy,zz,map[N*N][2],V ,ans,minn=50,tot,vis[N*N],top,s[N*N]; void dfs(int x){ for(int i=1;i<=tot;i++) if(!vis[i]&&(map[i][0]==x||map[i][1]==x)){ vis[i]=1; dfs(map[i][0]+map[i][1]-x); s[++top]=i; } } int main(){ while(scanf("%d%d",&xx,&yy)&&xx&&yy){ st: minn=min(minn,min(xx,yy)); scanf("%d",&zz); tot++; map[zz][0]=xx;map[zz][1]=yy; V[xx]++;V[yy]++; } for(int i=1;i<=45;i++)if(V[i]&1)ans++; if(!ans){ dfs(minn); for(int i=top;i;i--)printf("%d ",s[i]); puts(""); } else puts("Round trip does not exist."); scanf("%d%d",&xx,&yy); top=tot=ans=0;minn=50; memset(V,0,sizeof(V)); memset(vis,0,sizeof(vis)); if(xx)goto st; else return 0; }
Code length竟然进了前5
我只想问 第一名怎么23B写完的!!!
相关文章推荐
- Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
- win2003分布式文件系统(dfs)配置方法[图文详解]
- win2003分布式文件系统及其部署 图文教程
- Hadoop2.6+jdk8的安装部署(1)——使用jar包安装部署【详细】
- Hadoop FS Shell
- DFS使用方法总结
- FastDFS注意事项
- 无忧技术带您预览DFS(分布式文件系统)管理控制台
- C 语言实现迷宫 DFS算法
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- 一幅图弄清DFT与DTFT,DFS的关系
- HDFS---Namenode
- HDFS ---- Services startup
- POJ 2159 Ancient Cipher
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers