题意

定义一个01串若其奇数位为回文或者其偶数位为回文则是个好串,问长度为n字典序第K小的好串是什么。

题解

比较套路的暴力找第k大问题,每次从高位枚举是0还是1,之后统计填0时候方案可行的方案数(使用容斥)若方案数<k说明该为是1则将k减去求的的然后,否则该位是0继续枚举。

代码

/***     author:     TelmaZzzz*     create:     2019-10-05-11.07.16
**/
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(db &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const db &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define erp(x,y,z) for(int x=y;x>=z;x--)
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
#define Fi first
#define Se second
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}
void TelmaZzzz(){#ifndef ONLINE_JUDGEfreopen("1.txt","r",stdin);
#endif
}int n;
int pos_odd;
int pos_even;
int pos_odd_last;
int pos_even_last;
int ans[N];
bool flag1,flag0;
ll Pow(int x){x=min(x,61);ll res=1;ll p=2;while(x){if(x%2==0) {p*=p;x/=2;}else {res*=p;x--;}}return res;
}
ll cal(int x){int ra0=(n/2-x/2);int ra1=((n+1)/2-(x+1)/2);int rmi0=max(0,(n/2+1)/2-x/2);int rmi1=max(0,((n+1)/2+1)/2-(x+1)/2);//cout<<x<<' '<<ra0<<' '<<ra1<<' '<<rmi0<<' '<<rmi1<<' '<<flag0<<' '<<flag1<<' '<<k<<endl;ll tmp0,tmp1,tmp2;if(flag0){tmp0=Pow(ra1+rmi0);}else tmp0=0;if(flag1){tmp1=Pow(ra0+rmi1);}else tmp1=0;if(flag1&&flag0){tmp2=Pow(rmi1+rmi0);}else tmp2=0;//cout<<tmp1<<' '<<tmp0<<' '<<tmp2<<endl;return tmp1+tmp0-tmp2;
}
void update(int x){int mi0,mi1;if(n%2==0){mi0=n/2+1;mi1=n/2;}else {mi0=n/2+1;mi1=n/2+1;}if(x%2==0){if(x>mi0){if(ans[mi0*2-x]!=ans[x]) flag0=false;}}else {if(x>mi1){if(ans[mi1*2-x]!=ans[x]) flag1=false;}}
}
int main(){TelmaZzzz();//ios::sync_with_stdio(false);int t;R(t);ll k;int ti=0;while(t--){R(n,k);flag1=flag0=true;for(int i=1;i<=n;i++){ans[i]=0;bool tm1=flag1,tm0=flag0;update(i);ll tmp=cal(i);//cout<<tmp<<endl;if(k>tmp){k-=tmp;flag1=tm1;flag0=tm0;ans[i]=1;update(i);}}//cout<<k<<endl;if(k>1){printf("Case #%d: NOT FOUND!\n",++ti);}else {printf("Case #%d: ",++ti);for(int i=1;i<=n;i++){printf("%d",ans[i]);}puts("");}}//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;return 0;
}

gym 101194 B Hemi Palindrome相关推荐

  1. 2016-2017 ACM-ICPC CHINA-Final(EC-final) 题解(10 / 12)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2016-2017 ACM-ICPC CHINA-Final 比赛链接:https://codefor ...

  2. 2016-2017 ACM-ICPC CHINA-Final Solution

    Problem A. Number Theory Problem Solved. 水. 1 #include<bits/stdc++.h> 2 3 using namespace std; ...

  3. Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest

    比赛链接: http://codeforces.com/gym/100676 题目链接: http://codeforces.com/gym/100676/attachments/download/3 ...

  4. 【LeetCode】Palindrome Partitioning 解题报告

    [题目] Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...

  5. 强化学习(三) - Gym库介绍和使用,Markov决策程序实例,动态规划决策实例

    强化学习(三) - Gym库介绍和使用,Markov决策程序实例,动态规划决策实例 1. 引言 在这个部分补充之前马尔科夫决策和动态规划部分的代码.在以后的内容我会把相关代码都附到相关内容的后面.本部 ...

  6. Gym - 102082G

    Gym - 102082G https://vjudge.net/problem/2198225/origin 对于数列中任意一个数,要么从最左边到它不递减,要么从最右边到到它不递减,为了满足这个条件 ...

  7. 234. Palindrome Linked List - Easy

    Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false ...

  8. LeetCode 125 Valid Palindrome(有效回文)(*)

    版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/5062 ...

  9. Lintcode108 Palindrome Partitioning || solution 题解

    [题目描述] Given a strings, cutsinto some substrings such that every substring is a palindrome. Return t ...

最新文章

  1. android 入门
  2. rsync常用的三种用法
  3. Java 强、弱、软、虚,你属于哪一种?
  4. c语言中x的n次方怎么表示_线性代数的本质及其在AI中的应用
  5. xshell最多支持4个_中集拉钢卷专用挂车来了!自重5吨,最多能装4个钢卷
  6. Box2D实现Super Mario之关键技术分析——mario下蹲通过低矮障碍物
  7. Python_Bool
  8. Centos7 安装MySQL5
  9. 解决删除symantec,需要输入密码的问题
  10. 上下文无关文法和语言
  11. prolog寻找三角形个数
  12. How to change exchange rate in miro manually?
  13. 一文了解数据分析师与商业分析师的区别(一)
  14. 【Fusion】Conic Quadratic Optimization
  15. 第四篇、代理模式详解(三种)
  16. 室友在宿舍玩游戏我学java_在宿舍写代码总被一个室友认为在装逼,该怎么办?...
  17. 2021年上海市安全员C证考试报名及上海市安全员C证找解析
  18. 【外卖cps源码分享】支持美团饿了么
  19. 智能体适能训练评估系统-体姿体态评估系统软件
  20. 基于Go语言GoFrame+Vue+ElementUI实现的权限控制系统

热门文章

  1. 记录总结-如何逮捕实验室的老鼠
  2. CSS常用样式属性有哪些?代码怎么写?
  3. 一、zabbix快速入门
  4. 全球首发!老子云支持三维格式多达66种,可解决95%模型展示难题
  5. 远程桌面端口修改.bat
  6. Matlab—绘图保存为视频VideoWrite()函数用法与自定义视频尺寸
  7. 计组——从一道计算题题开始,展开关于总线平均传输速率的分析
  8. python 局域网dhcp嗅探_bettercap xerosploit 内网嗅探与劫持
  9. python中拼音怎么用_实用小技巧,Python一秒将汉字转为拼音
  10. 【windows自动备份】