Codeforces 325E
Codeforces 325E
原题
题目描述:给出\(n\)个点, 编号为\(0 \text ~ n-1\),每个点连出两条边分别为\(2i\)和\(2i+1\)(\(mod n\)),现从\(0\)出发,最后回到\(0\),且每个点必须且只到达一次(\(0\)为两次),输出一条可行路径。
solution
能发现\(2i=2(i+n/2)(mod n), 2i+1=2(i+n/2)+1(mod n)\),那就可以把\(i\)与\((i+n/2)\)看做一个点,原图变成一个\(n/2\)点\(n\)边图,每条边都要经过一次,也就是欧拉回路,然后搜索求解就好了。
code
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
using namespace std;
const int maxn=int(1e5)+100;
int n, sum;
int route[maxn];
bool vis[maxn];
void dfs(int cur)
{
if (vis[cur]) return;
vis[cur]=true;
dfs((cur*2)%n);
dfs((cur*2+1)%n);
route[++sum]=cur;
}
void solve()
{
dfs(0);
for (int i=sum; i>0; --i) printf("%d ", route[i]);
printf("0\n");
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d", &n);
if (n & 1) printf("-1\n");
else solve();
return 0;
}
Codeforces 325E的更多相关文章
- CodeForces - 325E:The Red Button (哈密尔顿 转 欧拉回路)
Piegirl found the red button. You have one last chance to change the inevitable end. The circuit und ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- Flask把变量注册到模板中
使用python的Flask框架时,参考<Flask Web开发>一书时,发现书中可以在全局使用Permission.FOLLOW变量. 但是自己在尝试是,确提示变量没有定义.经过搜索,找 ...
- CURL 和LIBCURL C++代码 上传本地文件,好不容易碰到了这种折腾我几天的代码
解决了什么问题:curl在使用各种方式上传文件到服务器.一般的文件上传是通过html表单进行的,通过CURL可以不经过浏览器,直接在服务器端模拟进行表单提交,完成POST数据.文件上传等功能. 服务器 ...
- 【python】中文的输出,打印,文件编码问题解决方法
直接在python中输入中文的字符串会报编译错误SyntaxError: Non-ASCII character,因为python文件默认编码方式是ASCII.如果想要打印中文字符,有两种方式: 1. ...
- C#、VB.NET 使用System.Media.SoundPlayer播放音乐
原文:C#.VB.NET 使用System.Media.SoundPlayer播放音乐 同步播放: System.Media.SoundPlayer player = new System.Media ...
- openjpa框架入门_项目 database 启动project 初始化(三)
mysql数据库安装好,这里不多说,现在来执行sql脚本 http://download.csdn.net/detail/shenhonglei1234/6019677 将下载好的脚本后缀名“open ...
- DM368启动串口打印分析
DM36x initialization passed! TI UBL Version: 1.50 Booting Catalog Boot Loader //启动目 ...
- python官方文档
Tutorialstart here Library Referencekeep this under your pillow Language Referencedescribes syntax a ...
- Ubuntu 14.04 下使用IDEA开发Spark应用 入门
网上有很多教程,有用sbt ,也有不用sbt的,看的头大,搞了半天,终于运行成功一个例子,如下: 1.官网下载http://www.jetbrains.com/idea/download/ Inter ...
- 无组件客户端js图片压缩
<div class="free-upload"> <p>上传您的约会照片,一张合影.一张票据哦!</p> <div class=&quo ...
- N1必备外来语
201412: キャリア: ノルマ:(normal)定额,劳动基本定额. チーフ: コスト: バンド:[英] band;皮带,腰带:吹奏乐团,轻音乐乐团(演奏者の一団.楽団.楽隊):营居群 [2014 ...