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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 小记:对Android网络下载工具的初步封装!(包括json,字符串下载(volley),和图片下载(glide))
import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkIn ...
- 山寨QQ音乐的布局(二)终于把IOS6的UITableView拍扁了
IOS应用开发中UITableView的应用十分广泛,但是IOS7神一样的把UITableView拍扁了,这样一来IOS6的UITableView不干了,就吵着也要被拍扁,那好吧我今天就成全了你... ...
- android--graphics
Color类 Constants |____BLACK, BLUE, CYAN Methods |____argb,rgb,alpha, red, green, blue |____parseColo ...
- java中内存结构及堆栈详解
一. java内存结构 1. Heap(堆):实例分配的地方,通过-Xms与-Xmx来设置 2. MethodArea(方法区域):类的信息及静态变量. 对应是Permanet Generation, ...
- linux下修改ip地址,默认网关以及DNS
*修改IP地址 即时生效: ifconfig eth0 192.168.1.100 netmask 255.255.255.0 重启生效: vim /etc/sysconfig/network-s ...
- 常用的IO流
常用的IO流 •根据处理数据类型的不同分为:字节流和字符流 •根据数据流向不同分为:输入流和输出流 字节流:字节流以字节(8bit)为单位,能处理所有类型的数据(如图片.avi等). 字节输入流:In ...
- HTTP based RESTful APIs - asp.net web api
1.HTTP http://www.w3.org/Protocols/rfc2616/rfc2616.html 2.REST是什么http://www.ics.uci.edu/~fielding/pu ...
- JIRA官方:JIRA源代码集成
防火墙后的Git 使用Atlassian Stash创建和管理Git存储库,设置细粒度的权限并在代码上协作.这一切—安全.快速.可靠,更重要的是,可以部署在防火墙后面.JIRA问题关键字自动将JIRA ...
- Eclipse被汉化后恢复EN模式
问题描述: 在安装Flush builder 的时候安装了汉化包,导致Eclipse中功能显示为汉字. 问题解决: 在Eclipse快捷方式下“目标”路径中添加-nl "EN"即可 ...
- poj 2632 Crashing Robots_模拟
做的差点想吐,调来调去,编译器都犯毛病,wlgq,幸好1a. 题意:给你机器人怎走的路线,碰撞就输出 #include <cstdlib> #include <iostream> ...