题目即要求构造一个长为$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的更多相关文章

  1. HDU 5816 Hearthstone

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Descript ...

  2. HDU5816 Hearthstone(状压DP)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an online collec ...

  3. 多校7 HDU5816 Hearthstone 状压DP+全排列

    多校7 HDU5816 Hearthstone 状压DP+全排列 题意:boss的PH为p,n张A牌,m张B牌.抽取一张牌,能胜利的概率是多少? 如果抽到的是A牌,当剩余牌的数目不少于2张,再从剩余牌 ...

  4. HDU 5816 Hearthstone (状压DP)

    Hearthstone 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an onlin ...

  5. HDU5816 Hearthstone

    Hearthstone                                                                        Time Limit: 2000/ ...

  6. HDU 5816 Hearthstone 概率dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5816 Hearthstone Time Limit: 2000/1000 MS (Java/Othe ...

  7. hdu-5816 Hearthstone(状压dp+概率期望)

    题目链接: Hearthstone Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Other ...

  8. 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 ...

  9. Programming a Hearthstone agent using Monte Carlo Tree Search(chapter one)

    Markus Heikki AnderssonHåkon HelgesenHesselberg Master of Science in Computer Science Submission dat ...

随机推荐

  1. maven配置下载包 解决SunCertPathBuilderException:unable to find valid certification path to requested target

    ​ 解决 『SunCertPathBuilderException:unable to find valid certification path to requested target』 问题 ★ ...

  2. 简单的 Go 入门教程

    Go(又称 Golang )是 Google 开发的一种静态强类型.编译型.并发型,并具有垃圾回收功能的编程语言 Docker 和 Kubernetes 都是使用 Go 进行开发的,这几年 Go 越来 ...

  3. vue基本指令与脚手架基本配置

    脚手架(@vue/cli)创建项目启动服务 1.创建项目 vue create 项目名字 2.启动项目 进入项目根目录,运行以下命令 yarn serve 3.脚手架目录代码分析 ├── node_m ...

  4. C++的智能指针学习笔记(初)

    C++ primer plus 16.2节介绍了auto_ptr,该模板类在C++11中已弃用,目前已被shared_ptr代替. auto_ptr又叫做智能指针,用于管理动态内存分配的用法. 为什么 ...

  5. [JVM-6]类加载器

    定义 前面说过加载阶段是一个可以让设计人员高度自控的模块,因为类文件的源头可以是多种多样的,代码生成.反射生成或从网络中生成等.因此类加载器作为对这些文件的处理就显得尤为重要. 但类加载器的功能不仅如 ...

  6. Python代码阅读(第21篇):将变量名称转换为蛇式命名风格

    Python 代码阅读合集介绍:为什么不推荐Python初学者直接看项目源码 本篇阅读的代码实现将变量名称转换为蛇式命名风格(snake case)的功能. 本篇阅读的代码片段来自于30-second ...

  7. 【UE4】GAMES101 图形学作业4:贝塞尔曲线

    总览 Bézier 曲线是一种用于计算机图形学的参数曲线. 在本次作业中,你需要实现de Casteljau 算法来绘制由4 个控制点表示的Bézier 曲线(当你正确实现该算法时,你可以支持绘制由更 ...

  8. 【数据结构与算法Python版学习笔记】查找与排序——散列、散列函数、区块链

    散列 Hasing 前言 如果数据项之间是按照大小排好序的话,就可以利用二分查找来降低算法复杂度. 现在我们进一步来构造一个新的数据结构, 能使得查找算法的复杂度降到O(1), 这种概念称为" ...

  9. nssm.exe使用方法

    nssm no-sucking service manager 1. 安装服务命令 nssm install <servicename> nssm install <servicen ...

  10. 0x04

    二分: while(l<r) { int mid=(l+r)/2; if(符合条件) r=mid; else l=mid+1; } 固定下二分的写法: 终止条件:l==r: 取mid=(l+r) ...