博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MemSQL start[c]up Round 1.E
阅读量:4329 次
发布时间:2019-06-06

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

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

拿到题目就觉得是规律题加构造题, 然后找了了几个小时无果,只知道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 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define INF 0x3fffffff#define N 100100struct node{ int to,next;}edge[2*N];void check(){ int n=18; for(int i=0;i
que[2];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=0; memset(pre,-1,sizeof(pre)); memset(g,-1,sizeof(g)); memset(mark,0,sizeof(mark)); int n; scanf("%d",&n); if(n%2!=0) { printf("-1"); return 0; } for(int i=0;i
tmp1) { tmp1=a[ g[tmp][i] ]; id=g[tmp][i]; } } tmp=id; save[cnt1++]=tmp; mark[tmp]=1; if(tmp==0) break; } for(int i=0;i

 

 

转载于:https://www.cnblogs.com/chenhuan001/p/3189732.html

你可能感兴趣的文章
百度移动搜索主要有如下几类结果构成
查看>>
Python爬虫面试题170道:2019版【1】
查看>>
JavaBean规范
查看>>
第四阶段 15_Linux tomcat安装与配置
查看>>
NAS 创建大文件
查看>>
学习笔记-模块之xml文件处理
查看>>
接口测试用例
查看>>
面试:用 Java 实现一个 Singleton 模式
查看>>
Sybase IQ导出文件的几种方式
查看>>
案例:手动输入一个字符串,打散放进一个列表,小写字母反序 大写字母保持不变...
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>
阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
查看>>
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>
设计原理+设计模式
查看>>
音视频处理
查看>>
tomcat 7服务器跨域问题解决
查看>>
前台实现ajax 需注意的地方
查看>>