UVA10054The Necklace
来源:互联网 发布:s5700 telnet 默认端口 编辑:程序博客网 时间:2024/05/18 00:51
UVA-10054
题意:给出若干个珠子,每个珠子两端都有颜色,两个珠子相同颜色的一端可以接在一起,问给出的能不能串成一个项链。
解题思路:能不能串成一串,明显又是欧拉回路。所有点的度都要为偶数。是欧拉回路的条件下,DFS遍历输出。
额,要注意点,点的坐标是1-50,,不是1-n。
/************************************************************************* > File Name: UVA-10054.cpp > Author: Narsh > > Created Time: 2016年07月22日 星期五 10时24分23秒 ************************************************************************/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;int map[1100][1100],d[1010],n,m,t,num=0;void dfs(int x) { for (int i = 1; i <= 50; i++) if (map[x][i]) { d[x]--; d[i]--; map[x][i]--; map[i][x]--; dfs(i); printf("%d %d\n",i,x); }}int main() { //freopen("xx.in","r",stdin); scanf("%d",&t); while (t--) { int a,b; scanf("%d",&n); memset(map,0,sizeof(map)); memset(d,0,sizeof(d)); for (int i = 1; i <= n; i++) { scanf("%d%d",&a,&b); map[a][b]++; map[b][a]++; d[a]++;d[b]++; } int f=1; for (int i = 1; i <= 50; i++) if (d[i] % 2 != 0) { f=0; break; } printf("Case #%d\n",++num); if (!f) printf("some beads may be lost\n"); else { for (int i = 1; i <= 50; i++) if (d[i]) dfs(i); } if (t) printf("\n"); }}
0 0
- UVA10054The Necklace
- UVA10054The Necklace
- necklace
- Broken Necklace
- Broken Necklace
- Broken Necklace
- Broken Necklace
- Broken Necklace
- Broken Necklace
- J - Necklace
- hdu3489 Necklace
- hdu3091 Necklace
- broken necklace
- THUSC2011 necklace
- Broken Necklace
- Broken Necklace
- Broken Necklace
- Broken Necklace
- 【工具】sublime中用到的插件
- @property关键字介绍及使用
- 循环冗余校验检错方案(CRC)
- 并查集算法和路径压缩
- IOS事件学习总结
- UVA10054The Necklace
- 使用WinDbg —— .NET篇 (十一)
- 用rem来做响应式开发
- hdu 1233 (最小生成树 简单例题)
- HDU 1867 A + B for you again 数据结构+KMP简单应用
- java设计模式之简单工厂模式
- 用oop 写 单机剪刀石头布游戏(内含有测试类)
- CopyOnWrite分析
- strom架构和构建Topology