Integer Numbers

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on ZJU. Original ID: 3365
64-bit integer IO format: %lld      Java class name: Main

Special Judge
 

The boy likes numbers. He has a sheet of paper. He have written a sequence of consecutive integer numbers on the sheet. The boy likes them.

But then the girl came. The girl is cruel. She changed some of the numbers.

The boy is disappointed. He cries. He does not like all these random numbers. He likes consecutive numbers. He really likes them. But his numbers are not consecutive any more. The boy is disappointed. He cries.

Help the boy. He can change some numbers. He would not like to change many of them. He would like to change as few as possible. He cannot change their order. He would like the numbers to be consecutive again. Help the boy.

Input

The first line of the input file contains n --- the number of numbers in the sequence (1 ≤ n ≤ 50000). The next line contains the sequence itself --- integer numbers not exceeding 109 by their absolute values.

There are multiple cases. Process to the end of file.

Output

Output the minimal number of numbers that the boy must change. After that output the sequence after the change.

Sample Input

6
5 4 5 2 1 8

Sample Output

3
3 4 5 6 7 8
 

Source

Author

Andrew Stankevich
 
解题:很容易发现规律,比如 1 2 3 4 5 6,你发现什么了?任意两个数字的差 恰好等于 他们的位置之差,所以只要统计各数字跟自己位置的差就可以了,看看哪种差最多!取差最多的那种,当然要修改的数字就最小了。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
vector<int>g[maxn];
int lisan[maxn],d[maxn],n;
int main() {
while(~scanf("%d",&n)){
for(int i = ; i < n; ++i){
g[i].clear();
scanf("%d",d+i);
lisan[i] = d[i] - i;
}
sort(lisan,lisan+n);
int cnt = ;
for(int i = ; i < n; ++i)
if(lisan[cnt-] != lisan[i]) lisan[cnt++] = lisan[i];
for(int i = ; i < n; ++i){
int index = lower_bound(lisan,lisan+cnt,d[i]-i)-lisan;
g[index].push_back(i);
}
int idx = -,mx = ;
for(int i = ; i < cnt; ++i)
if(g[i].size() > mx) mx = g[idx = i].size();
printf("%d\n",n - g[idx].size());
int tmp = g[idx][];
tmp = d[tmp] - tmp;
for(int i = ; i < n; ++i)
printf("%d%c",tmp + i,i+ == n?'\n':' ');
}
return ;
}

最新文章

  1. linux 系统工具集
  2. Install CentOS 7 on Thinkpad t430
  3. poj2676 Sudoku(DFS)
  4. Nginx禁止通过IP,未绑定域名访问服务器
  5. TPL(Task Parallel Library)多线程、并发功能
  6. java利用反射调用类的某个方法
  7. idea maven 无法加载已经安装的模块
  8. 轻量级代码生成器-OnlyCoder
  9. 解析spring循环依赖策略
  10. npm lodash
  11. ibatis项目应用
  12. requests库入门02-简单了解HTTP协议
  13. Unity项目中文字的统一管理
  14. dmi-ipmi
  15. 操作Linux系统环境变量的几种方法
  16. Mybatis进阶学习笔记——动态代理方式开发Dao接口、Dao层(推荐第二种)
  17. django高并发优化
  18. PHP守护进程化
  19. 使用CefSharp在.Net程序中嵌入Chrome浏览器(三)——基本操作
  20. ElasticStack系列之十六 &amp; ElasticSearch5.x index/create 和 update 源码分析

热门文章

  1. vue2 在methods 中无法获取this对象
  2. python_字典的使用
  3. luogu 1865 数论 线性素数筛法
  4. 51 nod 1693 水群
  5. 每天学点Python之comprehensions
  6. oracle刚開始学习的人经常使用操作100问
  7. php利用href进行页面传值的正确姿势
  8. mobiscroll手机端插件 好用(时间、日历、颜色)
  9. nyoj--983--首尾相连数组的最大子数组和(动态规划)
  10. vue-cli全引入jquery