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 ...
随机推荐
- PL/SQL Developer使用
查询存储过程方法:1.右上角小百页 - 新建SQL窗口 - 复制存储过程名称 - 按住CTRL - 点击链接进入2.点击查询按钮(望远镜) - 文本查找输入名称 - 对象类型默认(函数.过程,包说明, ...
- MHA学习笔记
MHA是一款开源的MySQL高可用程序,为MySQL主从复制架构提供了节点故障转移功能,当 master发生故障时MHA会自动提升拥有最新数据的slave节点成为新的主节点,还提供了master节 点 ...
- ecshop常用语句
ecshop之中的IF语句: <select name="product_cat" id="product_cat" class="form-c ...
- yii在TbGridView的td里面加入相应的下拉选项(转)
当你需要在一个GridView渲染某一个复杂元素的时候(特别是在这种情况下,这是一个小部件),这就需要你在控制器中调用一个动作.例如你给一个GridView的定义这样的一列: <?php $th ...
- 使用PyInstaller将Python程序打包成一个单独的exe文件
1. 安装步骤略过 网上教程多 2. 用cmd进入PyInstaller的目录 然后执行以下命令: python pyinstaller.py -F C:\test.py 以上命令需要把Python目 ...
- Java字符判断
从键盘上输入一个字符串,遍历该字符串中的每个字符,若该字符为小写字母,则输出“此字符是小写字母”:若为大写字母,则输出“此字符为大写字母”:否则输出“此字符不是字母”. 代码入下: import ja ...
- 清理文件默认打开方式.bat
@echo offsetlocal enabledelayedexpansionset "ext=%~x1":loopif defined ext set "ext=!e ...
- MarkDown写作技巧
前言 年轻的我们往往苦恼于没有充实的社会经历.社会阅历,很难有较强的个人能力.个人魅力!就个人能力而言,本 人主要把它分为两种:“吸收能力”和“输出能力”.吸收能力主要体现了个人对外界知识的摄入能力, ...
- SPARK 数据统计程序性能优化。
昨天写完R脚本 没测试就发到博客里, 结果实际运行发现很慢,运行时间在2小时以上, 查看spark控制台, 大量时间消耗在count上, 产生的stage多大70多个 . 分析原因. 1 selec ...
- 实战Django:简易博客Part1
舍得学习新技能的时候,通常不喜欢傻读书--捧着一本阐述该项技能的书籍,然后傻看,一路看下来,脑子里塞满了新的概念.知识点,头是越来越大,但技能却几乎没掌握半分. 多年来,舍得养成了用做实例来学习新技能 ...