ZOJ 3365 Integer Numbers

Source: Internet
Author: User
Tags integer numbers
Integer NumbersTime Limit: 1000 msMemory Limit: 32768 KBThis problem will be judged on ZJU. Original ID: 3365
64-bit integer IO format: % lld Java class name: MainSpecial 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 wocould not like to change ratio of them. he wowould like to change as few as possible. he cannot change their order. he wowould like the numbers to be consecutive again. help the boy.

Input

The first line of the input file containsN--- 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
65 4 5 2 1 8
Sample Output
33 4 5 6 7 8
  SourceAndrew Stankevich's Contest #11 AuthorAndrew Stankevich: It's easy to find patterns, such as 1 2 3 4 5 6. What did you find? The difference between any two numbers is exactly the same as the difference between their positions. Therefore, you only need to calculate the difference between each number and its own position to see which difference is the most! If the difference is the most, the number to be modified is the smallest.
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <algorithm> 6 # include <climits> 7 # include <vector> 8 # include <queue> 9 # include <cstdlib> 10 # include <string> 11 # include <set> 12 # include <stack> 13 # define LL long long14 # define pii pair <int, int> 15 # define INF 0x3f3f3f16 using namespace std; 17 const int maxn = 51000; 18 vector <int> g [maxn]; 19 int lisan [ Maxn], d [maxn], n; 20 int main () {21 while (~ Scanf ("% d", & n) {22 for (int I = 0; I <n; ++ I) {23g [I]. clear (); 24 scanf ("% d", d + I); 25 lisan [I] = d [I]-I; 26} 27 sort (lisan, lisan + n); 28 int cnt = 1; 29 for (int I = 1; I <n; ++ I) 30 if (lisan [cnt-1]! = Lisan [I]) lisan [cnt ++] = lisan [I]; 31 for (int I = 0; I <n; ++ I) {32 int index = lower_bound (lisan, lisan + cnt, d [I]-I)-lisan; 33g [index]. push_back (I); 34} 35 int idx =-1, mx = 0; 36 for (int I = 0; I <cnt; ++ I) 37 if (g [I]. size ()> mx) mx = g [idx = I]. size (); 38 printf ("% d \ n", n-g [idx]. size (); 39 int tmp = g [idx] [0]; 40 tmp = d [tmp]-tmp; 41 for (int I = 0; I <n; ++ I) 42 printf ("% d % c", tmp + I, I + 1 = n? '\ N': ''); 43} 44 return 0; 45}
View Code

 

ZOJ 3365 Integer Numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.