博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths
阅读量:4315 次
发布时间:2019-06-06

本文共 1366 字,大约阅读时间需要 4 分钟。

题目链接:

题意:

给四个不同点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
#include
#include
#include
#include
using namespace std;int n, m;const int maxn = 1111;int arr[maxn],mp[maxn];int arr2[maxn];int main() { int a, b, c, d; while (scanf("%d%d", &n, &m) == 2 && n) { scanf("%d%d%d%d", &a, &b, &c, &d); if (n ==4 || m < n + 1) { printf("-1\n"); continue; } memset(mp, 0, sizeof(mp)); memset(arr, 0, sizeof(arr)); mp[a] = mp[b] = mp[c] = mp[d] = 1; arr[1] = a; arr[n] = b; arr[2] = c; arr[4] = d; int tot = 5; for (int i = 1; i <= n; i++) { if (mp[i]) continue; if (arr[3] == 0) arr[3] = i; else { arr[tot++]= i; } } for (int i = 1; i < n; i++) printf("%d ", arr[i]); printf("%d\n", arr[n]); memset(arr2, 0, sizeof(arr2)); arr2[1] = c; arr2[n] = d; arr2[2] = arr[1]; arr2[3] = arr[3]; tot = 4; for (int i = n; i >=5; i--) arr2[tot++] = arr[i]; for (int i = 1; i < n; i++) printf("%d ", arr2[i]); printf("%d\n", arr2[n]); } return 0;}

 

转载于:https://www.cnblogs.com/fenice/p/5536676.html

你可能感兴趣的文章
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>
人工智能暑期课程实践项目——智能家居控制(一)
查看>>
前端数据可视化插件(二)图谱
查看>>
kafka web端管理工具 kafka-manager【转发】
查看>>
获取控制台窗口句柄GetConsoleWindow
查看>>
Linux下Qt+CUDA调试并运行
查看>>
51nod 1197 字符串的数量 V2(矩阵快速幂+数论?)
查看>>
OKMX6Q在ltib生成的rootfs基础上制作带QT库的根文件系统
查看>>
zabbix
查看>>
多线程基础
查看>>
完美解决 error C2220: warning treated as error - no ‘object’ file generated
查看>>
使用SQL*PLUS,构建完美excel或html输出
查看>>
前后台验证字符串长度
查看>>
《算法导论 - 思考题》7-1 Hoare划分的正确性
查看>>
win64 Python下安装PIL出错解决2.7版本 (3.6版本可以使用)
查看>>
获取各种类型的节点
查看>>
表达式求值-201308081712.txt
查看>>
centos中安装tomcat6
查看>>