sgu101:Domino
来源:互联网 发布:我的世界js手机版视频 编辑:程序博客网 时间:2024/05/22 03:12
完结usaco之后,终于踏上了sgu的征程,High aim,high demand !
第一题(忽略A+B)是一道图论题
以多米诺骨牌为边,数字抽象为点(0到6)
如果奇点个数为0个,求解欧拉回路
如果奇点个数为2个,求解欧拉路径
非以上情况No Solution
如果图不是连通的那么也是No Solution
不是难题,题解也不会很详细,大牛勿喷...
#include <stdio.h>#include <string.h>int N;int Edge[105][2] = {0}; int map[105][105] = {0};int degree[105] = {0};int E[105][105][55] = {0};int path[105][2] = {0}, top = 0;void dfs(int cur){ int i; for(i = 0; i <= 6; ++i) if(map[cur][i]) { map[cur][i]--; map[i][cur]--; dfs(i); path[N - top][0] = cur; path[N - top++][1] = i; }}void print(){ int i, x, y; for(i = 1; i <= top; ++i) { x = path[i][0]; y = path[i][1];if(E[x][y][0]) printf("%d +\n", E[x][y][E[x][y][0]--]);else if(E[y][x][0]) printf("%d -\n", E[y][x][E[y][x][0]--]); }} int main(){ int i, j; int x, y; int odd = 0; scanf("%d", &N); for(i = 1; i <= N; ++i) { scanf("%d%d", &x, &y); Edge[i][0] = x, Edge[i][1] = y; degree[x]++, degree[y]++; map[x][y]++, map[y][x]++; E[x][y][++E[x][y][0]] = i; } for(i = 0; i <= 6; ++i) if(degree[i] & 1) odd++; if(odd == 0) { for(i = 0; i <= 6; ++i) if(degree[i]) break;dfs(i);if(top < N) puts("No solution");else print(); } else if(odd == 2) { for(i = 0; i <= 6; ++i) if(degree[i] & 1) break;dfs(i);if(top < N) puts("No solution");else print(); } else puts("No solution"); return 0;}
0 0
- SGU101 Domino
- sgu101:Domino
- SGU101 Domino
- SGU101 Domino
- sgu101: Domino
- SGU101 Domino
- SGU101 - Domino(欧拉路)
- SGU101 Domino 留坑
- SGU101 Domino(欧拉回路)
- SGU101
- Sgu101
- sgu101
- SGU101 DFS
- SGU101----110
- SGU101欧拉回路
- sgu101-欧拉回路
- domino
- Domino
- hdu 2828 Lamp(重复覆盖)
- C# 扩展系统类string的方法
- 写给2016年11月8日的自己
- 【网络爬虫】【python】网络爬虫(二):网易微博爬虫软件开发实例(附软件源码)
- linux安装git协议步骤以及可能出现的问题
- sgu101:Domino
- 听摇滚如何入门?
- 最大子数组问题
- BZOJ 2120 数颜色 暴力
- Sicily 1415. Honeycomb Walk
- 数学公式
- 求两个排序数组的交集
- [leetcode] Evaluate the value of reverse polish expression
- Codeforces 97B Superset 平面分治