正题

题目链接:https://www.luogu.com.cn/problem/AT2363


题目大意

给出\(n\),要求构造一个字符串\(s\),使得能够找出恰好\(n\)个子序列使得这个子序列能划分成前后相等的两份。

要求\(|s|\leq 200\),字符集为\([1,100]\)

\(1\leq n\leq 10^{12}\)


解题思路

很妙的想法,我们把\(s\)分成两半,一半是\(1\sim x\),然后后一半是一个\(1\sim x\)的排列,这样答案就是这个排列的上升子序列数。

这样就化成了一个很简单的构造了,从小到大加,加到前面就是\(+1\),后面就是\(\times 2\)。


code

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
ll n,cnt,flag;deque<ll> q;
signed main()
{
scanf("%lld",&n);n++;
for(ll i=63;i>=0;i--){
if(flag){
cnt++;
q.push_back(cnt);
}
if((n>>i)&1){
if(flag)cnt++,q.push_front(cnt);
flag=1;
}
}
printf("%lld\n",cnt*2);
for(ll i=1;i<=cnt;i++)
printf("%lld ",i);
for(ll i=1;i<=cnt;i++)
printf("%lld ",q.front()),q.pop_front();
return 0;
}

最新文章

  1. 每天一个linux命令(26):用SecureCRT来上传和下载
  2. 无法删除对象 &#39;产品&#39;,因为该对象正由一个 FOREIGN KEY 约束引用。
  3. ORACLE查出表所有的触发器及触发器详细信息
  4. 非常难得的iPad版房地产售楼助手应用
  5. iPad 3g版完美实现打电话功能(phoneitipad破解)
  6. Linux下搭建Oracle11g RAC(7)----安装Oracle 软件
  7. c++设置输出精度
  8. 查看.a架构文件
  9. 自动删除超过30天文件的vbs脚本【转发】
  10. Could not load file or assembly……
  11. python基础---面向对象的概念
  12. 《转》studio界面、快捷键
  13. ZOJ Problem Set - 3706
  14. 面试3——java集合类总结(List)
  15. Http协议中Cookie详细介绍(转)
  16. [SD2015]序列统计——solution
  17. MySQL案例03:(MyCAT报错) [ERROR][$_NIOREACTOR-3-RW] caught err: java.lang.OutOfM emoryError: Unable to acquire 131072 bytes of memory, got 0
  18. hybrid app开发中用到的html5新特性localStorage、sessionStorage和websql database
  19. Elasticsearch 架构原理
  20. Oracle Database 12.2新特性详解

热门文章

  1. 数据结构与算法-排序(十)桶排序(Bucket Sort)
  2. 你真的了解JS里的&quot;new&quot;吗?
  3. Saruman's Army
  4. IO流(File类--递归--过滤器--IO字节流--IO字符流--Properties集合--缓冲流--转换流--序列化流--打印流)
  5. ajax无法返回视图
  6. 高德地图——添加标记的两种方法&amp;删除地标记的两种方法
  7. redhat9 linux 网卡无法激活排障
  8. mybatis第一个程序随笔
  9. vue 引入 tcplayer,并且实现视频点播,腾讯点播
  10. kubeadm方式搭建K8S集群