Integer Numbers
Time Limit: 1 Second Memory Limit: 32768 KB 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
Author: Andrew Stankevich
Source: Andrew Stankevich's Contest #11
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string> using namespace std; const int SZ = ;
int n, a[SZ];
map<int, pair<int, int> > cnt; int main()
{
while(scanf("%d", &n) != EOF)
{
cnt.clear();
for(int i = ; i < n; i++)
{
scanf("%d", a + i);
int x = a[i] - i;
if(cnt.find(x) == cnt.end())
{
cnt[x] = make_pair(i, );
}
else
{
cnt[x].second++;
}
}
int max = -, p;
for(map<int, pair<int, int> >::iterator it = cnt.begin(); it != cnt.end(); it++)
{
if((it->second).second > max)
{
max = (it->second).second;
p = (it->second).first;
}
}
printf("%d\n", n - max);
for(int i = a[p] - p; i < a[p]; i++)
printf("%d ", i);
printf("%d", a[p]);
for(int i = a[p] + ; i < a[p] + n - p; i++)
printf(" %d", i);
printf("\n");
}
return ;
}
Integer Numbers的更多相关文章
- ZOJ 3365 Integer Numbers
Integer Numbers Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...
- NYOJ题目436sum of all integer numbers
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr0AAAHKCAIAAACBiWRrAAAgAElEQVR4nO3dP1LjSts34G8T5CyEFB
- 【CSU 1556】Pseudoprime numbers
题 Description Jerry is caught by Tom. He was penned up in one room with a door, which only can be op ...
- UVALive 7279 Sheldon Numbers (暴力打表)
Sheldon Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/H Description According t ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- 关于Object数组强转成Integer数组的问题:Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
一.当把Object数组,强转的具体的Integer数组时,会报错. 代码如下: //数组强转报错演示 Object[] numbers = {1,2,3}; Integer[] ints = (In ...
- Code Signal_练习题_Circle of Numbers
Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distan ...
- Codeforces 600A. Extract Numbers 模拟
A. Extract Numbers time limit per test: 2 seconds memory limit per test: 256 megabytes input: standa ...
- SGU 140. Integer Sequences 线性同余,数论 难度:2
140. Integer Sequences time limit per test: 0.25 sec. memory limit per test: 4096 KB A sequence A is ...
随机推荐
- 【转】utf-8与Unicode的转化
作者:uuspider链接:https://www.zhihu.com/question/23374078/answer/65352538来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业 ...
- centos7环境下mysql安装
1.去官网下载合适的yum源安装包 https://dev.mysql.com/downloads/repo/yum/ 2.yum 本地安装 命令:yum localinstall mysql57-c ...
- android入门 — Activity启动模式
1.standard模式 standard模式是系统的默认启动方式,每次激活Activity都会创建Activity,并放在任务栈中. 系统不会在乎活动是否已经存在于返回栈中,每次启动都会创建该活动的 ...
- python获取前几天的时间
days的参数就是你想获取前多少天的数据,如果是昨天的话,则days=1 import datetime today=datetime.date.today() oneday=datetime.tim ...
- Halcon 笔记3 形态学
Halcon 三大数据类型: (1)图像 (2)区域 (3)XLD 查看时间工具 如果想让图像减少,则进行腐蚀(或者使用开运算),反之,则进行膨胀(或闭运算) 腐蚀后再进行膨胀,相当于进行开运算.因 ...
- 在MFC中显示cmd命令行
添加函数 void InitConsoleWindow1() { ; FILE* fp; AllocConsole(); nCrt = _open_osfhandle((long)GetStdHand ...
- asp.netMVC中权限控制论
这里设想了一个简单的思路,如果用户登录了,也就是session中有值才可以在控制器中操作,这样先添加一个控制器,如下代码: public class AuthController : Controll ...
- asp.net mvc4+EF 下使用UEditor
一.从官方网站下载UEditor,http://ueditor.baidu.com/website/download.html, 我下载的是1.53.net版本
- USB硬件接口相关
1.USB 设备端的D+为何要拉一个1.5K电阻到3.3v上?(USB是5v供电,但通信的电平是3.3v,所以上拉电平为3.3v:若要上拉到5v,则上拉电阻为10k) usb有主从设备之分,主设备有: ...
- Django之CSS,JS静态文件的配置
一. 专门创建一个目录放静态文件,即CSS,JS等. 1)先把jquery.min拿过来. 2)新建一个CSS文件放入样式 3)在login.html中引入.css文件 在login.html中引入. ...