【CF325E】The Red Button
来源:互联网 发布:复制信息打开手机淘宝 编辑:程序博客网 时间:2024/06/03 20:05
一个n个点的图,标号0 ~ n-1,第i个点向2 * i和2 * i + 1连边,构造哈密顿回路。
首先发现n为奇数无解。考虑转换为欧拉回路,将2 * i 与2 * i + 1合并为一点,这样点就转化为边了。
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#define Rep(i, x, y) for (int i = x; i <= y; i ++)#define Dwn(i, x, y) for (int i = x; i >= y; i --)#define RepE(i, x) for(int i = pos[x]; i; i = g[i].nex)using namespace std;typedef long long LL;const int N = 200005;struct Edge { int x, y, z, nex; } g[N * 2];int n, m, pos[N], sz, p[N], ans[N], az; bool vis[N];void Init(int x, int y, int z) { g[++ sz] = (Edge) { x, y, z, pos[x] }, pos[x] = sz; }void Dfs(int x) {RepE(i, x) if (!vis[i]) {vis[i] = 1, Dfs(g[i].y), p[++ m] = i;}}int main(){scanf ("%d", &n);if (n % 2) { puts("-1"); return 0; }Rep(i, 0, n / 2 - 1) Init(i, ((i * 4 % n) / 2 + 1) % (n/2), 1), Init(i, (i * 4 % n) / 2, 0);Dfs(0);Dwn(i0, m, 1) {int i = p[i0], x = g[i].x, y = g[i].y;ans[++ az] = 2 * x + g[i].z;}Rep(i, 1, az) printf("%d ", ans[i]);puts("0");return 0;}
0 0
- 【CF325E】The Red Button
- CF MemSQL Round1 E. The Red Button
- [CF 325E]The Red Button解题报告
- swift实现的Dont Tap the Red Button游戏iOS源码
- Arduino开发之Digital Push Button(Red)
- WinForm Controls And The Red X
- OpenGL Programming Guide or 'The Red Book'
- Hymn to the red October (zz)
- Red-black tree from the Wikipedia
- NOJ [1274] The battle of Red Cliff
- Win32 Series - The Button Class
- Upgrading the delete confirmation button
- Red
- red
- The insertion and deletion of the Red-Black Tree
- use slider to realize the button function
- how to disable the button when submitting
- 第九章子窗口 The Button Class
- ACM题目中输入数据的处理(C++版)
- AutoLayout自定义布局基础
- 适配iOS9系统
- 黑盒测试目标
- Spring 集成Quartz Scheduler 定时调度任务 Example
- 【CF325E】The Red Button
- C语言之转义字符、变量的内存机制
- java 终端输入小结,输入到数组、文件等(持续更新)
- leetcode112 Path Sum
- 利用DOMContentLoaded判断DOM是否加载完毕
- ArrayList实现原理
- Linux初步学习(文件权限的三个命令)
- eclipse安装ADT
- 【AndroidUI控件】如何动态的设置Relative Layout中按钮的layout_align_parent_right属性