题目链接:

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. responseXML 属性

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs ...

  2. SQL语句统计一段时间内的记录数

    实际应用中经常需要统计单位时间的记录数: 一个小时: SELECT ),createdate,) AS 日期 ,DATEPART(hh,createdate) AS 小时,COUNT(*)AS 记录 ...

  3. Cassandra 备份 - 1 - 节点镜像恢复

    之前比较关注如何使用Cassandra,但是真正想大规模使用前提还是需要搞清楚备份机制,确保数据安全. 本文主要内容来自文档 "Cassandra2.2"的翻译.最后部分为真实操作 ...

  4. 工作中nginx配置文件的一些参数记录

    reset_timedout_connection on 告诉nginx关闭不响应的客户端连接.这将会释放那个客户端所占有的内存空间 tcp_nopush on 告诉nginx在一个数据包里发送许多个 ...

  5. ubuntu打开 txt 文件乱码

    ubuntu12.04 gedit 打开 windows 分区中的 txt 文件乱码,是因为 ubuntu 和 windows 两个系统的编码不同.解决办法:终端里依次输入以下2 条命令即可: 代码: ...

  6. 利用HttpWebRequest访问WebApi

    WebApi现在越来越流行,下面给出利用HttpWebRequest访问WebApi的工具方法: 1.利用基准URL和参数字典生成完整URL /// <summary> /// 生成URL ...

  7. Hadoop1.x与2.x安装笔记

    Hadoop1.x与2.x安装笔记 Email: chujiaqiang229@163.com 2015-05-09 Hadoop 1.x 安装 Hadoop1.x 集群规划 No 名称 内容 备注 ...

  8. python杂记-3(购买商品)

    #!/usr/bin/env python# -*- coding: utf-8 -*-#如下是一个购物程序:#先输入工资,显示商品列表,购买,quit退出,最后格式化输出所买的商品.count = ...

  9. html中调用silverlight中的方法

    在xaml页面中放置一个textblock控件来绑定数据 <ItemsControl   x:Name="cityname">            <Items ...

  10. Moses更改权重的命令变化 -d -t -

    -l  可以用: weight-l 或者lm  (不需要在前面加-)   还是用-weight-overwrite “Distortion0= 0"更保险 reording weight i ...