Codeforces 673D Bear and Two Paths (贪心构造)
来源:互联网 发布:数据产品经理发展前景 编辑:程序博客网 时间:2024/05/16 19:52
题意
给出n个点,给出a,b,c,d,求能不能用少于m的边构成两条欧拉路
一条从a开始到b一条从c开始到d。
思路
因为m只有上限没有下限,我们贪心的构造就可以了,也就是说除了a,b,c,d其他的点都用相同的路径,这样就能使得路径最少了。
需要注意的是n等于4的时候。
代码
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <list>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define LL long long#define lowbit(x) ((x)&(-x))#define lson l, mid, rt << 1#define rson mid + 1, r, rt << 1|1#define MP(a, b) make_pair(a, b)const int INF = 0x3f3f3f3f;const int MOD = 1000000007;const int maxn = 1e5 + 10;const double eps = 1e-8;const double PI = acos(-1.0);typedef pair<int, int> pii;int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n, m, a, b, c, d; cin >> n >> m; cin >> a >> b >> c >> d; if (m < n - 1 + 2 || n == 4) return puts("-1"); vector<int> v; for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) v.push_back(i); } cout << a << " " << c << " "; for (int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << d << " " << b << endl; cout << c << " " << a << " "; for (int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << b << " " << d << endl; return 0;}
0 0
- Codeforces 673D Bear and Two Paths (贪心构造)
- Codeforces 673D Bear and Two Paths【贪心】
- CodeForces 673D Bear and Two Paths(构造)
- CodeForces 673D - Bear and Two Paths(构造)
- CodeForces 643 B.Bear and Two Paths(构造)
- codeforcs 351 D. Bear and Two Paths
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- Codeforces 318 div2.D Bear and Blocks(dp,贪心)
- codeforce之Bear and Two Paths
- Codeforces 14D Two Paths
- CodeForces 14D Two Paths
- codeforces 680D D. Bear and Tower of Cubes(dfs+贪心)
- Codeforces C - Bear and String Distance (贪心)
- CodeForces 385D Bear and Floodlight
- Codeforces 385 D Bear and Floodlight
- Codeforces Round #318-(D. Bear and Blocks)
- Codeforces Round #318 D. Bear and Blocks
- js实现关于数据字典的使用和数据存放的策略
- *关于音频焦点和音频竞争通道的问题
- c++作业5
- bzoj2595: [Wc2008]游览计划
- 软考程序员计算机专业英语
- Codeforces 673D Bear and Two Paths (贪心构造)
- NAT 苹果要求支持ipv6的原因吧。
- c++小游戏之贪吃蛇
- linux进程调度之 FIFO 和 RR 调度策略
- 字符串的全排列
- 提高篇项目4——求阶乘函数(1)
- ISA TEST黑客过关小游戏第二关解密
- 数据库索引的实现原理
- 数字三角形