题目链接:

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

    题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

    A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...

  9. 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 ...

随机推荐

  1. 一个用WPF做的简单计算器源代码

    一.界面设计XAML代码 <Window x:Class="fengjisuanqi.MainWindow" xmlns="http://schemas.micro ...

  2. [leetcode]_Valid Parentheses

    题目:判断给定字符串中的括号是否合法.题目中涉及三种符号'(' + ')' , '[' + ']' , '{' + '}'. 思路:利用stack来存储符号. 注意申请char型stack是: Sta ...

  3. java高级工程师必备知识

    成为Java高级工程师需要掌握哪些核心点? 每 逢长假都会有很多程序员跳槽,十一.过年是跳槽黄金时刻,尤其是过年.过年的时候年终奖到手,没有了多少牵挂,年终同学同事聚会比较多,沟通的就多,各种 工作机 ...

  4. php验证手机号码

    大家都应该有这个常识,中国的手机号码都是以数字“1”开头,然后利用“0~9”10个数字组成的11位数字组合,那么我们的验证规则肯定要根据这个思路来写. 根据上面的简单思路,我们便可以写下以下的验证代码 ...

  5. 通过API函数来控制SQLite数据库增删改查

    person类属性有Intenger id,String name,Intenger  age,相应的构造方法和set get方法. package com.xh.tx.dao; import and ...

  6. 关于EasyUI与富文本编辑器结合使用的问题(kindueditor与uueditor)

    最近使用easyui玩玩项目,在结合富文本编辑器时遇到了一些问题,很多人(在网上看到)集成富文本编辑器时常常不能显示, 第一次打开编辑的时候没有问题,但是第二次打开就出错了.为此我进行了一些调试研究. ...

  7. 5.html5中的路径表示

    路径在html中的作用主要是进行外部资源的引入,如css文件,js文件,媒体文件等. 而路径本身有分为相对路径和绝对路径.所谓相对路径,就是相对于链接页面而言的另一个页面的路径.而绝对路径,就是直接从 ...

  8. 在WPF中调用Winform控件

    最近在项目中用到了人脸识别和指纹识别,需要调用外部设备和接口,这里就用到了在WPF中调用Winform控件. 第一步,添加程序集引用.System.Windows.Forms和WindowsForms ...

  9. 菜鸟学习Hibernate——简单的增、删、改、查操作

    上篇博客利用Hibernate搭建起一个简单的例子,把数据库的映射显示了出来在上一篇的博客基础上这篇博客讲述如何利用Hinbernate框架实现简单的数据库操作. 1.加入junit.jar 2.新建 ...

  10. shell-IF判断

    #!/bin/bash echo "-----------------strat---------------" read -p "Enter a number:&quo ...