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 ...
随机推荐
- 团队开发——软件需求分析报告(Hello World 团队)
一. 项目名称 超级迷宫 二. 设计背景 随着生活节奏加快,游戏更新速度的加快,游戏大同小异缺少新颖度,同时为了满足多游戏的结合,充实人们的生活,同时增加知识,有协作模式增进友谊和感情,在闲暇 ...
- 基础系列(5)—— C#控制语句
语句是程序中最小程序指令.C#语言中可以使用多种类型的语句,每一种类型的语句又可以通过多个关键字实现.以下是C# 语言中使用的主要控制语句 类别 关键字 选择语句 if.else.switch.ca ...
- 【第四周】psp
代码累计 300+575+475+353=1603 随笔字数 1700+3000+3785+4210=12695 知识点 QT框架 Myeclipse基础环境 代码复用,封装 Ps技术 在excel画 ...
- 遍历frame中的表单:
遍历frame中的表单: public void table1() { // 查找frame List<WebElement> iframes = driver.findElements( ...
- paoding rose controller包及文件名命名规则
1.包命名规则:xxx.xxx.controllers(否则扫描不到)
- 第210天:node、nvm、npm和gulp的安装和使用详解
一.node 1.什么是node? 它不是JS文件,也不是JS框架,而是Server side JavaScript runtime,当服务端的一个JS文件运行时,会被NODE拦截,在NODE中运行J ...
- BZOJ4953 Wf2017Posterize(动态规划)
设f[i][j]为前i种强度选了j种且其中第i种选时前i个的最小误差.转移枚举上个选啥前缀和优化即可. #include<iostream> #include<cstdio> ...
- python中括号的使用
1. 列表list是用[ ]包住的以逗号分隔的数据集合 所有对列表的解析均采用[ ],不论是元素引用或取值 [ ]表示空列表 2. 字典由键-值(key-value)对构成,一般可采用{ }表示 取字 ...
- 【刷题】BZOJ 1095 [ZJOI2007]Hide 捉迷藏
Description 捉迷藏 Jiajia和Wind是一对恩爱的夫妻,并且他们有很多孩子.某天,Jiajia.Wind和孩子们决定在家里玩 捉迷藏游戏.他们的家很大且构造很奇特,由N个屋子和N-1条 ...
- 【BZOJ1391】Order(网络流,最小割)
[BZOJ1391]Order(网络流,最小割) 题面 BZOJ权限题... 良心洛谷 题目描述 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成 ...