hdu 5302 Connect the Graph(构造)
来源:互联网 发布:js 全部替换 编辑:程序博客网 时间:2024/05/21 06:54
题目链接:hdu 5302 Connect the Graph
当w1或者是b1为奇数时,无解。其他情况下一定可以构造出一条链和多个节点对,只要保证两点之间没有重边就行了。一种间隔1为一对,另一种间隔2为一对。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int N;int jump(int p, int k) {if (p == N)return 2;p += k;if (p > N)return p - 1;return p;}void solve (int n, int a1, int a2, int k) {int p = 1;for (int i = 0; i <= a2; i++) {int t = jump(p, k + 1);printf("%d %d %d\n", p, t, k);p = t;}p = jump(p, k + 1);for (int i = 1; i < a1; i++) {int t = jump(p, k + 1);printf("%d %d %d\n", p, t, k);p = jump(t, k + 1);}}int main () {int cas, w0, w1, w2, b0, b1, b2;scanf("%d", &cas);while (cas--) {scanf("%d%d%d%d%d%d", &w0, &w1, &w2, &b0, &b1, &b2);N = w0 + w1 + w2;if ((w1&1) || (b1&1)) {printf("-1\n");continue;}printf("%d\n", w1 / 2 + b1 / 2 + w2 + b2);solve(N, w1 / 2, w2, 0);solve(N, b1 / 2, b2, 1);}return 0;}
0 0
- hdu 5302 Connect the Graph(构造)
- 【HDU】 5302 Connect the Graph【构造】
- HDU 5302(Connect the Graph- 构造)
- HDU 5302 Connect the Graph (构造)
- HDOJ 5302 Connect the Graph 构造
- 多校第二场 1003 hdu 5302 Connect the Graph(构造)
- Hdu 5302 Connect the Graph 2015 Multi-University Training Contest 2
- HDU 6090 Rikka with Graph(构造)
- hdu5302 Connect the Graph 含spj
- uva 11387 - The 3-Regular Graph(构造)
- hdu 3371 Connect the Cities (prime)
- hdu 3371 Connect the cities (prim)
- HDU 4725 The Shortest Path in Nya Graph [构造 + 最短路]
- HDU 4725 The Shortest Path in Nya Graph(SPFA)
- hdu The Shortest Path in Nya Graph(建图+spfa)
- hdu 3371 Connect the Cities
- Hdu-3371 Connect the Cities
- HDU 3371 Connect the Cities
- 面试之二百度
- 九度oj 1020
- 去除搜狐快站底部版权
- System V IPC
- 排序算法(七)——堆排序
- hdu 5302 Connect the Graph(构造)
- Error Adding New Node To Rac Database
- 好的商业模式就是用技术打开的想象
- CodeForces 241A
- 001进制
- 持之于恒
- Java异常处理和设计
- 在PHP的函数前加上“@”的作用
- 1056. Mice and Rice (25)