http://codeforces.com/contest/288/problem/C

按二进制位从大到小进行匹配

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
template <class T> void checkmin(T &t,T x) {if(x < t) t = x;}
template <class T> void checkmax(T &t,T x) {if(x > t) t = x;}
template <class T> void _checkmin(T &t,T x) {if(t==-1) t = x; if(x < t) t = x;}
template <class T> void _checkmax(T &t,T x) {if(t==-1) t = x; if(x > t) t = x;}
typedef pair <int,int> PII;
typedef pair <double,double> PDD;
typedef long long ll;
#define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end ; it ++)
int a[1000100] , n , m , y , x , l;
ll r = 0;
int main() {cin >> n;m = n;for(int k=20;k>=0;k--) {x = (1 << k);if(n < x) continue;y = 4 * x - 2;l = n - x + 1;for(int i=0;i<l;i++) {a[x+i] = x-i-1;a[x-i-1] = x+i;r += y;}n -= 2 * l;}cout << r << endl;cout << a[0];for(int i=1;i<=m;i++) cout <<" "<< a[i];cout << endl;return 0;
}

转载于:https://www.cnblogs.com/aiiYuu/archive/2013/04/05/3000446.html

Codeforces Round #177 (Div. 1)C. Polo the Penguin and XOR operation【贪心】相关推荐

  1. Codeforces Round #579 (Div. 3) F2. Complete the Projects (hard version) dp + 贪心

    传送门 文章目录 题意: 思路: 题意: 思路: 排序方式跟easyeasyeasy版本的一样,但是hardhardhard版本是输出最多能选多少,所以我们对b<0b<0b<0的情况 ...

  2. Codeforces Round #579 (Div. 3) F1. Complete the Projects (easy version) 排序 + 贪心

    传送门 文章目录 题意: 思路: 题意: 思路: 比较直观的想法就是对于bi≥0b_i\ge0bi​≥0的项目,我们将aia_iai​从小到大排序,让后依次加bib_ibi​,如果有取不到的,显然就无 ...

  3. Codeforces Round #525 (Div. 2) D Ehab and another another xor problem

    题目:http://codeforces.com/contest/1088/problem/D 题目大意:有0 <= a , b <= 230的a,b两个整数,定义一次操作(c , d)的 ...

  4. Codeforces Round #555 (Div. 3), problem: (C2) Increasing Subsequence (hard version)【贪心+撞到南墙也不回头】

    题目链接 题目大意 复杂版大意是我们可以从左右两端每次拿走一个数,一直拿,不过要满足一个条件,每次拿的数要保证严格递增(即从小到大然后不会有相同的情况) 复杂版的话是会有相同的数字出现 在题解中正式说 ...

  5. 【Codeforces Round #525(Div. 2)】Ehab and another another xor problem(思维+异或)

    题目链接 D. Ehab and another another xor problem time limit per test 1 second memory limit per test 256 ...

  6. 【CodeForces - 289E 】Polo the Penguin and XOR operation (数学,异或,贪心)

    题干: Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 ...

  7. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  8. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  9. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

最新文章

  1. 用Windows Media Player截图的方法
  2. 保障K8s部署中的安全性
  3. ntoskrnl损坏
  4. 【Linux】服务器常用的操作命令
  5. 黑龙江认识电子计算机ppt,《第22课 不断发展的现代社会》优秀教案(黑龙江县级优课).docx...
  6. DDD领域驱动设计简介
  7. 【☢️伤害性不高,侮辱性极强!☢️】Win10更新21H1后关闭右下角天气和新闻
  8. 软考信息安全工程师学习笔记三(1.3 信息安全管理基础)
  9. NameNode之启动流程分析
  10. Qt——P9 信号和槽
  11. WebConfig配置文件详解
  12. std::thread
  13. 对于“增霸卡“的介绍跟使用
  14. 使用for循环打印出大写字母的ASCII码对照表(c语言实现)
  15. 独家 | 精彩!这27本书籍,每位数据科学家都应该阅读(附说明图表)
  16. Docker 学习笔记(四)-- Docker 可视化界面
  17. Python_day19--HTML基础--文本标签、超链接标签、图片标签
  18. AiraNg配合RileRun下载及观看神器,包括(Aria搭建方法,AriaNg搭建问题)
  19. 零知识证明:重要构造
  20. pytorch中的一维数组,是列向量还是行向量?

热门文章

  1. java—IO流——读取键盘输入的字母并转换成大写字母输出在控制台上
  2. Mr.J--贪吃蛇demo
  3. 血的教训--如何正确使用线程池submit和execute方法
  4. onclick 拼接时如何传递json对象
  5. Spring Bean的生命周期例子
  6. Python带参数的装饰器
  7. django学习随笔:ManagementUtility
  8. RTSP客户端接收存储数据(live555库中的openRTSP实例)
  9. Poj 1338 Ugly Numbers(数学推导)
  10. 转:DotNET企业架构应用实践-架构师成长之路-如何成为优秀架构师