Codeforces Beta Round #97 (Div. 1) A. Replacement 水题
2016-05-07 17:07
309 查看
A. Replacement
题目连接:
http://codeforces.com/contest/135/problem/ADescription
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 n space-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.Sample Input
xudyhduxyz5
1 2 3 4 5
Sample Output
1 1 2 3 4题意
你必须改变一个数,使得这个序列从小到大排序之后,字典序最小题解:
把最大值变成1就好了如果全是1,就把一个1变成2
代码
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5+7; int a[maxn],mx,n,mx2; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(a[i]>mx)mx=a[i],mx2=i; } if(mx==1)a[mx2]=2; else a[mx2]=1; sort(a+1,a+1+n); for(int i=1;i<=n;i++) printf("%d ",a[i]); printf("\n"); }
相关文章推荐
- 二叉树
- 求任意范围内回文素数c++解决方案(解决了地址释放的问题,附错误原因简述)
- 十六进制的编程
- 基于R-CNN的物体检测
- 机器学习中的数学(3)-模型组合(Model Combining)之Boosting与Gradient Boosting
- poj,1273Drainage Ditches
- 《Hibernate学习笔记十》:多对多关联关系详解
- Windows安装AndroidStudio开发软件
- 16进制的转换
- IOS NSTimer 定时器用法总结
- 第一章 JAVA入门(Hello World)
- 栈与队列的互相转化
- PowerDesigner 的 COMMENT注释
- 整理音乐
- 机器学习中的数学(2)-线性回归,偏差、方差权衡
- 【jQuery/CSS】显示或隐藏元素
- Object-c------NSArray的简单介绍
- C++实验五——数组的分离。
- dpdk编译安装
- 【2016】四月份英语学习总结