Number Sequence HDU - 5014
There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules:
● a i ∈ 0,n0,n
● a i ≠ a j( i ≠ j )
For sequence a and sequence b, the integrating degree t is defined as follows(“�” denotes exclusive or):
t = (a 0 � b 0) + (a 1 � b 1) +・・・+ (a n � b n)
(sequence B should also satisfy the rules described above)
Now give you a number n and the sequence a. You should calculate the maximum integrating degree t and print the sequence b.
Input
There are multiple test cases. Please process till EOF.
For each case, the first line contains an integer n(1 ≤ n ≤ 10 5), The second line contains a 0,a 1,a 2,…,a n.
Output
For each case, output two lines.The first line contains the maximum integrating degree t. The second line contains n+1 integers b 0,b 1,b 2,…,b n. There is exactly one space between b i and b i+1 (0 ≤ i ≤ n - 1). Don’t ouput any spaces after b n.
Sample Input
4
2 0 1 4 3
Sample Output
20
1 0 2 3 4
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;
typedef long long ll;
const int maxn=110000;
const int INF=0x3f3f3f3f;
ll a[maxn];
ll d[maxn];
int main()
{
ll n;
while(~scanf("%I64d",&n))
{
for(ll i=0; i<=n; i++)
scanf("%I64d",&a[i]);
memset(d,-1,sizeof(d));
ll ans=0;
for(ll i=n; i>=0; i--)
{
ll t=0;
if(d[i]==-1)
{
for(ll j=0;; j++)
{
if(!(i&(1<<j))) t+=(1<<j);
if(t>=i)
{
t-=(1<<j);
break;
}
}
ans+=(i^t)*2;
d[i]=t;
d[t]=i;
}
}
printf("%I64d\n",ans);
for(ll i=0; i<=n; i++)
printf(i==n?"%I64d\n":"%I64d ",d[a[i]]);
}
return 0;
}
Number Sequence HDU - 5014的更多相关文章
- (KMP 模板)Number Sequence -- Hdu -- 1711
http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/Other ...
- AC日记——Number Sequence hdu 1711
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Number Sequence(HDU 1005 构造矩阵 )
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Number Sequence HDU 1711(KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=1711 首次接触KMP,自己都不是特别理解.在网上百度看了好几个帖子之后,对KMP也有了初步的理解. #inclu ...
- Number Sequence - HDU 1711(KMP模板题)
题意:给你一个a串和一个b串,问b串是否是a串的子串,如果是返回b在a中最早出现的位置,否则输出-1 分析:应该是最简单的模板题了吧..... 代码如下: ==================== ...
- Number Sequence HDU 1711 KMP 模板
题目大意:两个数组匹配,求子串首次出现的位置. 题目思路:数组长度,比较大,朴素算法的时间复杂度为 m*n超时.KMP的时间复杂度为m+n可行. #include<iostream> #i ...
- Spring-1-H Number Sequence(HDU 5014)解题报告及测试数据
Number Sequence Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Pro ...
- ACM学习历程——HDU 5014 Number Sequence (贪心)(2014西安网赛)
Description There is a special number sequence which has n+1 integers. For each number in sequence, ...
- HDU 1711 Number Sequence(数列)
HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
随机推荐
- Windows下端口占用查看
假如我们需要确定谁占用了我们的80端口 1.Windows平台在windows命令行窗口下执行:C:\>netstat -aon|findstr "80" TCP 1 ...
- 【BZOJ1072】【SCOI2007】排列 [状压DP]
排列 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 给一个数字串s和正整数d, 统计s有多 ...
- bzoj 1774: [Usaco2009 Dec]Toll 过路费 ——(改)floyd
Description 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一系列的规章制度,使得任何一只奶牛在农场中的道路行走,都 要向农夫 ...
- Lua中调用C++方法
目前项目,使用了Lua脚本,至于使用Lua的好处不再赘述了.于是对Tolua做了一些小小的学习,总结一下吧. 主要说一下如何在Lua中调用C++方法. Lua调用C++的桥梁,是tolua.tolua ...
- 玩一下易语言 "和"字有多种读音,注定了它的重要性!!
变量名 类型 静态 数组 备注 拼音 文本型 0 测试的汉字 文本型 有几种发音 整数型 i 整数型 测试用的汉字 = “和” 有几种发音 = 取发音数目 ...
- sass_安装问题(ERROR: Could not find a valid gem 'sass' (>= 0), here is why: Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: cert)
安装sass前需安装ruby 安装好ruby好打开命令行,输入 gem install sass 出现错误: ERROR: Could not find a valid gem 'sass' (> ...
- Ribbon的主要组件与工作流程
一:Ribbon是什么? Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡算法,将Netflix的中间层服务连接在一起.Ribbon客户端组件提供一系列完善的配置项如连接 ...
- Part2-HttpClient官方教程-Chapter1-基础
前言 超文本传输协议(HTTP)可能是当今Internet上使用的最重要的协议.Web服务.网络支持的设备和网络计算的增长继续扩展了HTTP协议在用户驱动的Web浏览器之外的作用,同时增加了需要HTT ...
- IT界天才少年:比肩雷军、叫板任正非,自己作死了
两点之间,走弯路和走直路到达的终点是一样的,而他只是走了弯路,他曾在华为身居高位.后又创业.做投资,完全是不差钱的主. 他跌宕起伏的人生中充满传奇,成功.失败.遗憾.矛盾,每个词都不足以形容他,只有这 ...
- python基础===Windows环境下使用pip install 安装出错"Cannot unpack file"解决办法
不知道为什么,加了豆瓣镜像源还是不行 这个命令可以解决! pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douba ...