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 ;
}

ZOJ 3365 Integer Numbers的更多相关文章

  1. Integer Numbers

    ZOJ Problem Set - 3365 Integer Numbers Time Limit: 1 Second      Memory Limit: 32768 KB      Special ...

  2. zoj 1383 Binary Numbers

    Binary Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a positive integer n, print o ...

  3. NYOJ题目436sum of all integer numbers

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr0AAAHKCAIAAACBiWRrAAAgAElEQVR4nO3dP1LjSts34G8T5CyEFB

  4. zoj 3365 灵活数字规律

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3365 #include <cstdio> #incl ...

  5. ZOJ 1078 Palindrom Numbers

    原题链接 题目大意:判断一个数是不是palindrom.不限于十进制,可以在任何进制下判断. 解法:还好,数字的范围不大,int类型足够搞定.方法就是从2进制开始,先把数字转换成2进制,判断是否对称, ...

  6. ZOJ 1095 Humble Numbers

    原题链接 题目大意:定义了一种数字Humble Number,他们的质因数只包含2.3.5.7中的一个或者几个,求第n个这样的数,1<=n<=5842. 解法:一看到这道题又在想DFS了, ...

  7. zoj 3365

    题意 给你一个序列  改变尽可能少的数使其成为公差为一 递增的等差数列 可以将给你的序列减去一个等差数列 即num[i] -= i,若得到的数全部相等, 则说明给你的序列本身就满足条件  则只要寻求n ...

  8. zoj 1828 Fibonacci Numbers

    A Fibonacci sequence is calculated by adding the previous two members of the sequence, with the firs ...

  9. ZOJ 2588 Burning Bridges(求含重边的无向连通图的割边) - from lanshui_Yang

    Burning Bridges Time Limit: 5 Seconds Memory Limit: 32768 KB Ferry Kingdom is a nice little country ...

随机推荐

  1. iOS开发——自动填充短信验证码

    苹果在iOS 12,改进了一个很人性化的小细节.在做短信验证码功能的时候,自动获取短信中的验证码,然后点击填充即可.不用再向之前那样麻烦,自己看到弹出的短信信息后,死记硬背,再一个个敲上去,害怕背错了 ...

  2. web 安全主题

  3. Python 绘图与可视化 matplotlib(下)

    详细的参考链接:更详细的:https://www.cnblogs.com/zhizhan/p/5615947.html 图像.子图.坐标轴以及记号 Matplotlib中图像的意思是打开的整个画图窗口 ...

  4. python--(常用模块-3-正则表达式)

    python--(常用模块-3-正则表达式) 正则表达式是对字符串操作的⼀种逻辑公式. 我们⼀般使⽤正则表达式对字符串进⾏匹 配和过滤. 使⽤正则的优缺点: 优点: 灵活, 功能性强, 逻辑性强. 缺 ...

  5. JS侧边栏实现

    <!DOCTYPE html> <html lang="en"> <style> </style> <head> < ...

  6. 【BZOJ 1297】[SCOI2009]迷路

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点与点之间的距离都是1的话. 那么T次方之后的矩阵上a[1][n]就是所求答案了. 但是这一题的边权可能会大于1 但最多为10 ...

  7. Nutch的配置(使用MySQL作为数据存储)

    首先先从http://www.apache.org/dyn/closer.cgi/nutch/下载安装包 这里假定nutch的根目录为:${APACHE_NUTCH_HOME} 配置${APACHE_ ...

  8. WinServer-IIS-IP及域的限制

    如果启用域名限制,那么会对服务器产生比较大的资源开销,慎重选择这个 来自为知笔记(Wiz)

  9. Python中常见的文件对象内建函数

    文件对象内建方法列表 文件对象的方法 操作 file.close() 关闭文件 file.fileno() 返回文件的描写叙述符(file descriptor.FD,整数值) file.flush( ...

  10. STM32F407VG (四)时钟配置

    1.STM32 F407VG 的starup_stm32f40_41xxx.s的例如以下位置调用 IMPORT SystemInit,之后调用main函数,所以 进入main函数时候就已经自己主动完毕 ...