完全的乱搞题啊。。。 被坑的要死。

拿到题目就觉得是规律题加构造题, 然后找了了几个小时无果,只知道n为奇数的时候是一定无解的,然后当n为偶数的时候可能有很多解,但是如果乱选择的话,很有可能形成无解的情况。

然后想到了类似于估价函数之类的东西, 一开始我就想到了让几个关键的点设价值设成很大,然后在构造解的时候尽量不选这些点,然后。。。 发现数据到30左右就出错了。  然后再进一步的想,把每个点都估计一个价值,价值的大小为到0的距离。 然后就可以保证在构造解的时候尽量选离0远的点,这样一直选,一直选,一直选。。。就不可思议的过了。。。

不知道具体证明,但是思想感觉没有错误。因为这题无解的情况就是过早的选到了0. 如果每次都尽量选离0远的点,局部最优可以成为整体最优。

E. The Red Button
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Piegirl found the red button. You have one last chance to change the inevitable end.

The circuit under the button consists of n nodes, numbered from 0 to n - 1. In order to deactivate the button, the n nodes must be disarmed in a particular order. Node 0 must be disarmed first. After disarming node i, the next node to be disarmed must be either node(2·i) modulo n or node (2·i) + 1 modulo n. The last node to be disarmed must be node 0. Node 0 must be disarmed twice, but all other nodes must be disarmed exactly once.

Your task is to find any such order and print it. If there is no such order, print -1.

Input

Input consists of a single integer n (2 ≤ n ≤ 105).

Output

Print an order in which you can to disarm all nodes. If it is impossible, print -1 instead. If there are multiple orders, print any one of them.

Sample test(s)
input
2
output
0 1 0
input
3
output
-1
input
4
output
0 1 3 2 0
input
16
output
0 1 2 4 9 3 6 13 10 5 11 7 15 14 12 8 0

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff
#define N 100100 struct node
{
int to,next;
}edge[*N]; void check()
{
int n=;
for(int i=;i<n;i++)
{
int a=i*;
a=a%n;
int b=i*+;
b=b%n;
printf("%d: ",i);
if(a!=i)
printf("%d ",a);
if(b!=i)
printf("%d\n",b);
}
} int mark[N];
int g[N][];
int a[N];
int save[N];
queue<int > que[];
int cnt,pre[N]; void add_edge(int u,int v)
{
edge[cnt].to=v;
edge[cnt].next=pre[u];
pre[u]=cnt++;
} int main()
{
//check();
//freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
//freopen("//home//chen//Desktop//ACM//out.text","w",stdout); cnt=;
memset(pre,-,sizeof(pre));
memset(g,-,sizeof(g));
memset(mark,,sizeof(mark));
int n;
scanf("%d",&n);
if(n%!=)
{
printf("-1");
return ;
}
for(int i=;i<n;i++)
{
for(int j=;j<;j++)
{
int tmp=*i+j;
tmp=tmp%n;
g[i][j]=tmp;
add_edge(tmp,i);
}
}
memset(a,,sizeof(a));
////////////////////////////////////////// 还是要逆过来搜索
int a1=,b=;
que[a1].push();
int num=;
mark[]=;
while(que[a1].size()!=)
{
num++;
swap(a1,b);
while(que[b].size()!=)
{
int cur=que[b].front();
que[b].pop();
for(int p=pre[cur];p!=-;p=edge[p].next)
{
int v=edge[p].to;
if(mark[v]==)
{
mark[v]=;
a[v]=num;
que[a1].push(v);
}
}
}
} memset(mark,,sizeof(mark));
int cnt1=;
save[cnt1++]=;
mark[]=;
save[cnt1++]=;
int tmp=;
while()
{
int tmp1=-,id;
for(int i=;i<;i++)
{
if(mark[ g[tmp][i] ]==) continue;
if(a[ g[tmp][i] ] > tmp1)
{
tmp1=a[ g[tmp][i] ];
id=g[tmp][i];
}
}
tmp=id;
save[cnt1++]=tmp;
mark[tmp]=;
if(tmp==) break;
}
for(int i=;i<cnt1;i++)
printf("%d ",save[i]);
// if(cnt1!=n+1)
//printf("NO\n");
return ;
}

MemSQL start[c]up Round 1.E的更多相关文章

  1. MemSQL start[c]up Round 2 - online version C. More Reclamation(博弈)

    题目大意 额,写来写去,我还是直接说抽象之后的题目大意吧: 有一个 r*2 的矩形,两个人轮流的在矩形上面减去一个 1*1 的小正方形,要求在减的过程中,不能使矩形“断开”,也就是说,如果一个人减去了 ...

  2. MemSQL start[c]up Round 1.b

    二分查找题, 不知道用double的人,用LL果断错了... B. Stadium and Games time limit per test 1 second memory limit per te ...

  3. MemSQL start[c]up Round 2 - online version(DP)

    只有小写字母 那>=2600的直接找单字母串长度大于等于100的就可以了 <2600 的dp找最长回文串 #include <iostream> #include<cst ...

  4. codeforces MemSQL start[c]up Round 2 - online version B 最长公共子系列

    题目链接:  http://codeforces.com/contest/335/problem/B 分析: 第一眼看上去串的长度为5*10^4, 冒似只能用O(n)的算法可解. 而这样的算法从来没见 ...

  5. MemSQL start[c]up Round 1 B题

    题目链接 http://codeforces.com/contest/325/problem/B 第一遍写了暴搜,果断TLE 然后上了二分,结果120组数据只有第40组过不了,我就写了奇怪的东西... ...

  6. MemSQL Start[c]UP 2.0 - Round 1(无聊练手B题)

    http://codeforces.com/contest/452/problem/B   B. 4-point polyline time limit per test 2 seconds memo ...

  7. MemSQL Start[c]UP 2.0 - Round 2 - Online Round

    搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A #include<cstdio> ...

  8. MemSQL Start[c]UP 2.0 - Round 1

    A. Eevee http://codeforces.com/contest/452/problem/A 字符串水题 #include<cstdio> #include<cstrin ...

  9. MemSQL Start[c]UP 2.0 - Round 1 B. 4-point polyline (线段的 枚举)

    昨天cf做的不好,居然挂零了,还是1点开始的呢.,,, a题少了一个条件,没判断长度. 写一下B题吧 题目链接 题意: 给出(n, m),可以得到一个矩形 让你依次连接矩形内的4个点使它们的长度和最长 ...

随机推荐

  1. Java SSL证书的安装

    https正在成为主流,http估计在不久的将来会被彻底放弃…… 一个Java程序需要访问一个https的网站的时候,可能需要涉及证书的安装,卸载等操作. 一.证书的下载 打开浏览器输入https:/ ...

  2. linux学习规划

  3. Ubuntu 16.04下搭建kubernetes集群环境

    简介 目前Kubernetes为Ubuntu提供的kube-up脚本,不支持15.10以及16.04这两个使用systemd作为init系统的版本. 这里详细介绍一下如何以非Docker方式在Ubun ...

  4. 进程控制函数(1)-getpgid() getpgrp() 获取当前进程的进程组ID

    定义:pid_t getpid(void); 表头文件:#include<unistd.h> 说明:getpid()用来取得目前进程的进程识别码, 许多程序利用取到的此值来建立临时文件, ...

  5. 【C语言】22-枚举

    上一讲介绍了结构体类型,这讲就介绍C语言中的另一种数据类型---枚举类型.枚举类型在iOS中也是很常用的,用法跟Java中的枚举类似. 一.枚举的概念 枚举是C语言中的一种基本数据类型,并不是构造类型 ...

  6. C++中常函数内部的this指针也是const类型的

    代码中碰到一个奇怪的现象,在同样的函数中调用this指针,结果却有一个无法通过编译 // 读取连接信息 void ThirdWizardPage::ReadConnection() { QFile f ...

  7. C++的历史与现状

    在31年前(1979年),一名刚获得博士学位的研究员,为了开发一个软件项目发明了一门新编程语言,该研究员名为Bjarne Stroustrup,该门语言则命名为——C with classes,四年后 ...

  8. Ubuntu 安装HBase

    下载:http://mirror.bit.edu.cn/apache/hbase/stable/ 官方指南:http://abloz.com/hbase/book.html 安装配置: 解压: tar ...

  9. tiny4412 u-boot 启动参数的设置

    参考 http://www.cnblogs.com/chenfulin5/p/5887552.html 制作SD卡 u-boot 编译完之后, 进入 u-boot 目录里面的 sd_fuse cd ~ ...

  10. nginx的root alias 指令

    location /img/ { alias /var/www/image/; } #若按照上述配置的话,则访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件 ...