Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths
题目链接:
http://codeforces.com/contest/673/problem/D
题意:
给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d。
题解:
构造法,看例子:
input:
5 6
5 2 4 1
output:
5 4 3 1 2
4 5 3 2 1
所以只要满足k>=n+1,就可以构造出来答案。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std; int n, m; const int maxn = ;
int arr[maxn],mp[maxn];
int arr2[maxn]; int main() {
int a, b, c, d;
while (scanf("%d%d", &n, &m) == && n) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (n == || m < n + ) {
printf("-1\n"); continue;
}
memset(mp, , sizeof(mp));
memset(arr, , sizeof(arr));
mp[a] = mp[b] = mp[c] = mp[d] = ;
arr[] = a; arr[n] = b;
arr[] = c; arr[] = d;
int tot = ;
for (int i = ; i <= n; i++) {
if (mp[i]) continue;
if (arr[] == ) arr[] = i;
else {
arr[tot++]= i;
}
}
for (int i = ; i < n; i++) printf("%d ", arr[i]); printf("%d\n", arr[n]); memset(arr2, , sizeof(arr2));
arr2[] = c; arr2[n] = d; arr2[] = arr[]; arr2[] = arr[];
tot = ;
for (int i = n; i >=; i--) arr2[tot++] = arr[i];
for (int i = ; i < n; i++) printf("%d ", arr2[i]); printf("%d\n", arr2[n]);
}
return ;
}
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 构造
D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B
B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题
连接在这里,->点击<- A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabyte ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors
题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力
C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D
D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- C#局域网桌面共享软件制作(二)
链接C#局域网桌面共享软件制作(一) 如果你运行这个软件查看流量监控就会发现1~2M/s左右的上传下载,并且有时会报错“参数无效”,如果你将屏幕截图保存到本地的话每张图片大概4M(bmp).120KB ...
- 已经导入了具有相同的简单名称“Interop.DSOFramer, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null”的程序集。
错误 : 已经导入了具有相同的简单名称“Interop.DSOFramer, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null”的程序集. ...
- kvm介绍
KVM(Kernel-Based Virtual Machines)是一个基于Linux内核的虚拟化技术, 可以直接将Linux内核转换为Hypervisor(系统管理程 序)从而使得Linux内核能 ...
- 复习URLHttpConnection方式GET,POST方式链接网络解析uri
xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...
- .Net之美
第1章 C#类型基础 1.1 值类型和引用类型值类型和引用类型是以它们在计算机内存中是如何被分配的来划分的.值类型包括了结构和枚举,引用类型则包括了类. 接口. 委托等. 还有一种特殊的值类型,称为简 ...
- 学习simple.data之基础篇
simple.data是一个轻量级的.动态的数据访问组件,支持.net4.0. 1.必须条件和依赖性: v4.0 or greater of the .NET framework, or v2.10 ...
- pure css做的pc登陆界面
源码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- python 使用联动优势支付接口的sign与verify
直接上代码 if options.umpay_private_key is not None and len(options.umpay_private_key) > 0: try: with ...
- 一幅图证明chrome的由来和目的
- java-servlet-jsp
=========================servletjavax.servlet javax.servlet.http javax.annotation javax.ser ...