[gym103055H]Grammy and HearthStone
题目即要求构造一个长为$2n$的序列$a_{i}$,满足$\forall 1\le i\le n$,$i$恰好出现两次,假设分别是$a_{x}=a_{y}=i(x<y)$,即要求$y-x=i$
(输出序列即对于所有$i$,依次输出其第一次出现的位置$x$即可)
考虑$S_{1}=\sum_{i=1}^{n}x$(定义与之前相同)和$S_{2}=\sum_{i=1}^{n}y$,满足$\begin{cases}S_{2}-S_{1}=\frac{n(n+1)}{2}\\S_{1}+S_{2}=n(2n+1)\end{cases}$,将两式相减即可解得$S_{1}=\frac{n(3n+1)}{4}\in Z$
因此,有解的必要条件即$n\equiv 0,1(mod\ 4)$
接下来,对$n$分类讨论,并构造对应$a_{i}$:
当$n=4k$,令$a_{i}$为以下序列即可——
$$
\{4k,4k-2,...,2\}\{4k-1\}\{2,4,...,4k\}\\\{2k-1\}\{4k-3,4k-5,...,2k+1\}\{2k-3,2k-5,...,3\}\\\{4k-1,2k-1\}\{3,5,...,2k-3\}\{1,1\}\{2k+1,...,4k-3\}
$$
(特别的,当$n=4$时前者构造不合法,可以令$a_{i}=\{1,1,3,4,2,3,2,4\}$)
当$n=4k+1$,令$a_{i}$为以下序列即可——
$$
\{4k+1\}\{4k-2,4k-4...,2\}\{4k\}\{2,4,...,4k-2\}\\\{2k+1,4k+1\}\{4k-1,4k-3,...,2k+3\}\{2k-1,2k-3,...,3\}\\\{4k,2k+1\}\{3,5,...,2k-1\}\{1,1\}\{2k+3,2k+5,...,4k-1\}
$$


1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 1000005
4 int n,a[N<<1],ans[N];
5 void add(int x){
6 a[++a[0]]=x;
7 }
8 int main(){
9 scanf("%d",&n);
10 if ((n%4==2)||(n%4==3)){
11 printf("-1");
12 return 0;
13 }
14 if (n==4){
15 printf("1 5 3 4");
16 return 0;
17 }
18 if (n%4==0){
19 int k=n/4;
20 for(int i=4*k;i>=2;i-=2)add(i);
21 add(4*k-1);
22 for(int i=2;i<=4*k;i+=2)add(i);
23 add(2*k-1);
24 for(int i=4*k-3;i>=2*k+1;i-=2)add(i);
25 for(int i=2*k-3;i>=3;i-=2)add(i);
26 add(4*k-1),add(2*k-1);
27 for(int i=3;i<=2*k-3;i+=2)add(i);
28 add(1),add(1);
29 for(int i=2*k+1;i<=4*k-3;i+=2)add(i);
30 }
31 else{
32 int k=n/4;
33 add(4*k+1);
34 for(int i=4*k-2;i>=2;i-=2)add(i);
35 add(4*k);
36 for(int i=2;i<=4*k-2;i+=2)add(i);
37 add(2*k+1),add(4*k+1);
38 for(int i=4*k-1;i>=2*k+3;i-=2)add(i);
39 for(int i=2*k-1;i>=3;i-=2)add(i);
40 add(4*k),add(2*k+1);
41 for(int i=3;i<=2*k-1;i+=2)add(i);
42 add(1),add(1);
43 for(int i=2*k+3;i<=4*k-1;i+=2)add(i);
44 }
45 for(int i=1;i<=a[0];i++)
46 if (!ans[a[i]])ans[a[i]]=i;
47 for(int i=1;i<=n;i++)printf("%d ",ans[i]);
48 }
[gym103055H]Grammy and HearthStone的更多相关文章
- HDU 5816 Hearthstone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descript ...
- HDU5816 Hearthstone(状压DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an online collec ...
- 多校7 HDU5816 Hearthstone 状压DP+全排列
多校7 HDU5816 Hearthstone 状压DP+全排列 题意:boss的PH为p,n张A牌,m张B牌.抽取一张牌,能胜利的概率是多少? 如果抽到的是A牌,当剩余牌的数目不少于2张,再从剩余牌 ...
- HDU 5816 Hearthstone (状压DP)
Hearthstone 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an onlin ...
- HDU5816 Hearthstone
Hearthstone Time Limit: 2000/ ...
- HDU 5816 Hearthstone 概率dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Hearthstone Time Limit: 2000/1000 MS (Java/Othe ...
- hdu-5816 Hearthstone(状压dp+概率期望)
题目链接: Hearthstone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- Google Deepmind AI tries it hand at creating Hearthstone and Magic: The Gathering cards
http://www.techrepublic.com/article/google-deepmind-ai-tries-it-hand-at-creating-hearthstone-magic-t ...
- Programming a Hearthstone agent using Monte Carlo Tree Search(chapter one)
Markus Heikki AnderssonHåkon HelgesenHesselberg Master of Science in Computer Science Submission dat ...
随机推荐
- 10.11 HTTPS
没有HTTPS的抓包截图 HTTPS=HTTP + TLS/SSL https 实现过程如下 1.客户端发起HTTPS请求 rewrite www.baidu.com https://www.baid ...
- NOIP模拟73
T1 小L的疑惑 解题思路 第一眼不是正解,又是 bitset 优化可以得到的 60pts 的部分分. 打着打着突然发现这个东西好像和之前做过的某个题有一些相似,试着打了一下. 然后样例过了,然后对拍 ...
- NX屏蔽窗口的按钮
有时候在激活一个命令按钮的时候,需要同时禁止掉另外一个或多个命令按钮 ''' <summary> ''' 取按钮是否敏感 ''' </summary> ''' <para ...
- NXOpen.CAM.CAMSetup.CopyObjects的使用
复制CAM对象 Public Function CopyObjects(ByVal view As NXOpen.CAM.CAMSetup.View, ByVal objectsToBeMoved() ...
- 7-Zip
7-Zip https://www.7-zip.org/
- 使用寄存器点亮LED——2
1. 项目:使用stm32寄存器点亮LED, 分别点亮红.绿.蓝3个灯. 2. 步骤 先新建个文件夹保存项目 再新建项目 将startup_stm32f10x_hd.s拷贝到该文件夹下 新建main. ...
- 从源码层面深度剖析Redisson实现分布式锁的原理(全程干货,注意收藏)
Redis实现分布式锁的原理 前面讲了Redis在实际业务场景中的应用,那么下面再来了解一下Redisson功能性场景的应用,也就是大家经常使用的分布式锁的实现场景. 引入redisson依赖 < ...
- Go语言核心36讲(Go语言进阶技术六)--学习笔记
12 | 使用函数的正确姿势 在前几期文章中,我们分了几次,把 Go 语言自身提供的,所有集合类的数据类型都讲了一遍,额外还讲了标准库的container包中的几个类型. 在几乎所有主流的编程语言中, ...
- 关于takin-data,你想知道的都在这里(二)trace日志篇
相信大家在使用takin的过程中都见到过压测过程中实时展示的请求流量明细和请求详情了吧,像这样: 还有这样: 这样的请求流量明细和调用链详情是怎么实现的呢,今天就带大家探究下. 在前面的启动命令篇(h ...
- [no code][scrum meeting] Alpha 12
项目 内容 会议时间 2020-04-19 会议主题 周总结会议 会议时长 45min 参会人员 全体成员 $( "#cnblogs_post_body" ).catalog() ...