ZOJ 3365 Integer Numbers
Integer Numbers
This problem will be judged on ZJU. Original ID: 3365
64-bit integer IO format: %lld Java class name: Main
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
#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的更多相关文章
- Integer Numbers
ZOJ Problem Set - 3365 Integer Numbers Time Limit: 1 Second Memory Limit: 32768 KB Special ...
- zoj 1383 Binary Numbers
Binary Numbers Time Limit: 2 Seconds Memory Limit: 65536 KB Given a positive integer n, print o ...
- NYOJ题目436sum of all integer numbers
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr0AAAHKCAIAAACBiWRrAAAgAElEQVR4nO3dP1LjSts34G8T5CyEFB
- zoj 3365 灵活数字规律
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3365 #include <cstdio> #incl ...
- ZOJ 1078 Palindrom Numbers
原题链接 题目大意:判断一个数是不是palindrom.不限于十进制,可以在任何进制下判断. 解法:还好,数字的范围不大,int类型足够搞定.方法就是从2进制开始,先把数字转换成2进制,判断是否对称, ...
- ZOJ 1095 Humble Numbers
原题链接 题目大意:定义了一种数字Humble Number,他们的质因数只包含2.3.5.7中的一个或者几个,求第n个这样的数,1<=n<=5842. 解法:一看到这道题又在想DFS了, ...
- zoj 3365
题意 给你一个序列 改变尽可能少的数使其成为公差为一 递增的等差数列 可以将给你的序列减去一个等差数列 即num[i] -= i,若得到的数全部相等, 则说明给你的序列本身就满足条件 则只要寻求n ...
- zoj 1828 Fibonacci Numbers
A Fibonacci sequence is calculated by adding the previous two members of the sequence, with the firs ...
- ZOJ 2588 Burning Bridges(求含重边的无向连通图的割边) - from lanshui_Yang
Burning Bridges Time Limit: 5 Seconds Memory Limit: 32768 KB Ferry Kingdom is a nice little country ...
随机推荐
- freeswitch GUI界面(portal)
1.控制台 加载模块 load mod_xml_rpc 2.ip:8080/portal 进行登录 账号 : freeswitch 密码 : works 让模块随着freeswitch启动进行加载 ...
- 1、使用Python3爬取美女图片-网站中的每日更新一栏
此代码是根据网络上其他人的代码优化而成的, 环境准备: pip install lxml pip install bs4 pip install urllib #!/usr/bin/env pytho ...
- laydate 监听日期切换
```` //日期范围 laydate.render({ elem: '#Time', range: "至", max: gitData() ,done: function(val ...
- android studio2.2 配置NDK
1.配置环境: Android studio2.2 配置NDK NDK版本[android-ndk-r13b-windows-x86_64.zip] NDK下载网址:[https://dl.googl ...
- shell 键盘录入和运算
一.read 命令,从键盘读入数据,赋给变量 1.脚本代码 #!/bin/sh read arg1 arg2 echo "第一个参数: $arg1" echo "第二个参 ...
- Nginx 项目部署和配置
nginx 作为代理服务器,需要代理多个项目的话配置如下: server { listen 80; server_name localhost; #charset koi8-r; #ac ...
- 我一不小心把ubuntu里的ps这样的命令删掉了,应该怎么重装呢
sudo apt-get --reinstall install procps
- [ReactVR] Add Shapes Using 3D Primitives in React VR
React VR ships with a handful of 3D primitives. We'll importprimitives like <Sphere/>, <Box ...
- leetcode题解||ZigZag Conversion问题
problem: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of r ...
- 【Java】【Flume】Flume-NG启动过程源代码分析(一)
从bin/flume 这个shell脚本能够看到Flume的起始于org.apache.flume.node.Application类,这是flume的main函数所在. main方法首先会先解析sh ...