CodeForces 909F
题意略。
思路:
第一问:
递归地来写,找对称,发现关于(1<<y) - 1和(1<<y)对称的数字做 & 结果为0。
第二问:
6,7特殊考虑。循环左移(1<<y) ~ (1<<(y + 1) - 1),可以保证这个区间内的值与下标做 & 结果不为0。然而如果在这个段内只有1<<y这一个数,那么
我们无法循环左移,此时要特判为NO。
详见代码:
#include<bits/stdc++.h>
#define maxn 50
#define maxn2 100005
using namespace std; int one[maxn],tail;
int ans1[maxn2],ans2[maxn2];
int six[] = {,,,,,};
int seven[] = {,,,,,,}; void init(){
one[] = ;
tail += ;
for(int i = ;(<<i) - <= ;++i){
one[i] = (<<i) - ;
tail += ;
}
}
int cnt1(int x){
int ret = ;
while(x){
x = x & (x - );
++ret;
}
return ret;
}
void construct(int x){
if(x <= ) return;
int pos = lower_bound(one,one + tail,x) - one - ;
int mid = one[pos] + ;
for(int i = mid;i <= x;++i) swap(ans2[i],ans2[mid - (i - mid) - ]);
x = mid - (x - mid) - - ;
construct(x);
} int main(){
init();
int n;
scanf("%d",&n);
if(n & ) printf("NO\n");
else{
printf("YES\n");
for(int i = ;i <= n;++i) ans2[i] = i;
construct(n);
printf("%d",ans2[]);
for(int i = ;i <= n;++i) printf(" %d",ans2[i]);
printf("\n");
} if(n <= || cnt1(n) == ) printf("NO\n");
else if(n == ){
printf("YES\n");
printf("%d",six[]);
for(int i = ;i < ;++i) printf(" %d",six[i]);
printf("\n");
}
else if(n == ){
printf("YES\n");
printf("%d",seven[]);
for(int i = ;i < ;++i) printf(" %d",seven[i]);
printf("\n");
}
else{
printf("YES\n");
for(int i = ;i <= ;++i) ans1[i] = seven[i - ];
int lft = ,rht = min((lft<<) - ,n);
while(lft < n){
for(int i = lft;i <= rht;++i){
if(i < rht) ans1[i] = i + ;
else ans1[i] = lft;
}
lft = lft<<;
rht = min((lft<<) - ,n);
}
printf("%d",ans1[]);
for(int i = ;i <= n;++i) printf(" %d",ans1[i]);
printf("\n");
}
return ;
}
CodeForces 909F的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- python带有GIL解释器锁
1.GIL是什么?GIL的全称是Global Interpreter Lock(全局解释器锁),来源是python设计之初的考虑,为了数据安全所做的决定. 2.每个CPU在同一时间只能执行一个线程(在 ...
- <<Modern CMake>> 翻译 2.2 CMake 编程
<<Modern CMake>> 翻译 2.2 CMake 编程 流程控制 CMake有一个 if 语句, 经年累月之后,现在它已经相当复杂. 您可以在 if 语句中使用全大写 ...
- jQuery写toTop(回到顶部)效果
在通常的网站开发中,页面有时候会很长,尤其是一些电商网站,为了提高用户的体验效果,我们通常会增加一个回到顶部的按钮,这个按钮我们同城会使用fixed定位,将其定位在当前可视区域某一固定位置.这个效果用 ...
- 【Android】System.exit(0) 退出程序
许多 Android 应用程序都是连续点击两下返回键时退出程序,代码如下: private long exitTime = 0; @Override public boolean onKeyDown( ...
- ld: library not found for -
这几天在做微信登录,总是遇到这个问题,详细如下: ld: library not found for -lWeChatSDK clang: error: linker command failed w ...
- 解决微信小程序开发者工具输入框焦点问题
Windows10笔记本上运行微信小程序开发者工具,输入框(input,textarea)没有焦点,只能在真机调试,效率太低.后来发现是Window10对笔记本高分屏支持不好,要DPI缩放,导致兼容性 ...
- vue前后分离项目部署(不同端口号,nginx反向代理解决跨域问题)
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...
- ASP.NET Core on K8S深入学习(3)Deployment
上一篇<部署过程解析与安装Dashboard>中我们了解K8S的部署过程,这一篇我们来了解一下K8S为我们提供的几种应用运行方式:Deployment.DaemonSet与Job,它们是K ...
- 字符串(String、StringBuffer、StringBuilder)进阶分析
转载自https://segmentfault.com/a/1190000002683782 我们先要记住三者的特征: String 字符串常量 StringBuffer 字符串变量(线程安全) St ...
- 死磕JVM之类中各部分的加载顺序
话不多说,直接上代码: 1.通过new创建对象实例: 2.当对象中含有静态方法,且调用时: -- 调用父类静态方法: 总结: * 类中静态资源首次加载的时间是类中静态资源第一次被调用的时候或者该类的对 ...