codeforces 97 div2 C.Replacement 水题
2016-05-19 19:45
507 查看
C. Replacement
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all.
After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.
Input
The first line contains a single integer n (1 ≤ n ≤ 105), which represents how many numbers the array has. The next line contains nspace-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.
Output
Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.
Examples
input
output
input
output
input
output
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all.
After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.
Input
The first line contains a single integer n (1 ≤ n ≤ 105), which represents how many numbers the array has. The next line contains nspace-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.
Output
Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.
Examples
input
5 1 2 3 4 5
output
1 1 2 3 4
input
5 2 3 4 5 6
output
1 2 3 4 5
input
3 2 2 2
output
1 2 2 题意:改变一个数使得字典序最小; 思路:改变最大值;全是1是坑点;
#include<bits/stdc++.h> using namespace std; #define ll __int64 #define mod 1000000007 #define inf 100000000000005 #define MAXN 10000010 //#pragma comment(linker, "/STACK:102400000,102400000") int a[100010]; int main() { int x,y,z,i,t; scanf("%d",&x); for(i=0;i<x;i++) scanf("%d",&a[i]); sort(a,a+x); if(a[x-1]!=1) a[x-1]=1; else a[x-1]=2; sort(a,a+x); for(i=0;i<x;i++) printf("%d ",a[i]); return 0; }
相关文章推荐
- 破解基础篇五
- UVA 11020 Efficient Solutions set
- 【Spring】【笔记】《Spring In Action》第一章 读书笔记
- AJAX跨域整理
- Minimum Size Subarray Sum-最小长度字数组和问题
- phpexcel导出excel中文乱码问题解决
- 【bzoj4561】【JLOI2016】【圆的异或并】【扫描线+set】
- C51命令行生成hex
- 字符串九大系统函数
- Maven初步搭建 (一)
- nodejs npm
- day5.19总结_音乐播放器_页面更新和播放
- OSX PHP添加gettext支持
- 数据抓包(网络爬虫)-正方教务管理系统登录
- MySQL 索引原理及慢查询优化
- java jni jbyteArray传参给c++
- 字符串单双引号区别
- PAT (Advanced Level) 1028. List Sorting (25)
- Poj 2342 Anniversary party【入门树型dp】
- 练习011-012