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