HDU 4781 构造
来源:互联网 发布:怎么ping电脑端口号 编辑:程序博客网 时间:2024/05/21 22:47
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4781
题意: 构造出n个点m条边的图,要求边从1~-m只出现一遍,对于每个点存在回路且回路路径权值和为3的倍数
题解: 对于每个点i<n构造出i~i+1权值为i的边,用n~1调整权值构造出环,然后其余权值为w的边在i~j且i~j权值与w对3同余的路径上添加
代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int f[7000][4];int cnt[4];int c[7000];int main(){ int tt; scanf("%d", &tt); for(int ii = 0; ii < tt; ii++) { printf("Case #%d:\n", ii + 1); int n, m; scanf("%d%d", &n, &m); memset(c, 0, sizeof c); for(int i = 1; i < n; i++) { printf("%d %d %d\n", i, i + 1, i); c[i + 1] = c[i] + i; } cnt[0] = cnt[1] = cnt[2] = 0; for(int i = n; i <= m; i++) { int x = i % 3; f[++cnt[x]][x] = i; } int p = (3 - (c[n] - c[1]) % 3) % 3; printf("%d 1 %d\n", n, f[cnt[p]--][p]); for(int i = 1; i <= n - 2; i++) for(int j = i + 2; j <= n; j++) if(!(i == 1 && j == n)) { int p = (c[j] - c[i]) % 3; if(cnt[p]) printf("%d %d %d\n", i, j, f[cnt[p]--][p]); } //if(cnt[0] || cnt[1] || cnt[2]) cout << "-1" << endl; } return 0;}
0 0
- HDU 4781 构造
- hdu 4781 Assignment For Princess(构造法)
- HDU 4781 Assignment For Princess(构造)
- hdu 4781 Assignment For Princess 构造
- HDU 4781(图上的构造)
- hdu 4781 Assignment For Princess(构造)
- hdu 4781 Assignment For Princess(构造法)
- hdu 3306 矩阵构造
- HDU 3306 矩阵构造
- hdu 3483 矩阵构造
- hdu 4731 构造
- hdu 1588 构造矩阵
- HDU - 5301(构造)
- HDU 1757 矩阵构造
- HDU 4850 (构造 dfs)
- HDU 5386 构造
- hdu 5740(构造,KM)
- HDU 5847 构造
- 求海量个无序整数的中位数
- 安装DirectX SDK时出现Error Code:s1023 的解决方案
- android添加新键值
- 采用GUI编译xilinx的库文件
- The file “Pods.xcconfig” couldn’t be opened because there is no such file.
- HDU 4781 构造
- CAS SSO学习笔记
- ubuntu 10.10 添加系统调用的方法
- android 的四种枚举Context.MODE_PRIVATE
- 【一】【HTML基础】
- 序列化对象到磁盘上
- iOS开发中,如何合理地制造“BUG”并且查找BUG
- SVN常用命令
- IIS服务器代替VS自带的服务器