题目即要求构造一个长为$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. 运行WampServer提示计算机中丢失 msvcr110.dll

    ​ 在第一次运行WampServer的时候,出现"无法启动此程序,因为计算机中丢失 MSVCR110.dll.尝试重新安装该程序以解决此问题. ​ 在浏览器的地址栏里输入 http://ww ...

  2. 【Java技术专题】「性能优化系列」针对Java对象压缩及序列化技术的探索之路

    序列化和反序列化 序列化就是指把对象转换为字节码: 对象传递和保存时,保证对象的完整性和可传递性.把对象转换为有字节码,以便在网络上传输或保存在本地文件中: 反序列化就是指把字节码恢复为对象: 根据字 ...

  3. 【Java虚拟机8】自定义类加载器、类加载器命名空间、类的卸载

    前言 学习类加载器就一定要自己实现一个类加载器,今天就从一个简单的自定义类加载器说起. 自定义类加载器 例1 一个简单的类加载器,从一个给定的二进制名字读取一个字节码文件的内容,然后生成对应的clas ...

  4. 【UE4 设计模式】策略模式 Strategy Pattern

    概述 描述 策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法的变化不会影响到使用算法的客户. 套路 Context(环境类) 负责使用算法策略,其中维持了一 ...

  5. 【UE4 C++】打印字符串与输出日志

    打印屏幕 默认打印屏幕 // 打印至屏幕 FString screenMessage = "(AddOnScreenDebugMessage) Hello world!"; GEn ...

  6. djago后台管理页面

    from django.contrib import admin from blogtest.models import * #修改网页title和站点header.+ admin.site.site ...

  7. 微信小程序实现tabs选项卡

    选项卡在我们的日常开发中,使用的还是蛮多的,但是微信小程序中却没有直接提供选项卡组件,不过我们可以变通通过 scroll-view 和 swiper 组件来实现一个选项卡的功能. 需求: 实现一个选项 ...

  8. 计算机网络传输层之TCP流量控制

    文章转自:https://blog.csdn.net/weixin_43914604/article/details/105531547 学习课程:<2019王道考研计算机网络> 学习目的 ...

  9. binary-tree-postorder-traversal leetcode C++

    Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...

  10. std::string类详解

    之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够.字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至 ...