A. Replacement

题目连接:

http://codeforces.com/contest/135/problem/A

Description

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

xudyhduxyz

5

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");
}

Codeforces Beta Round #97 (Div. 1) A. Replacement 水题的更多相关文章

  1. Codeforces Beta Round #14 (Div. 2) A. Letter 水题

    A. Letter 题目连接: http://www.codeforces.com/contest/14/problem/A Description A boy Bob likes to draw. ...

  2. Codeforces Beta Round #97 (Div. 1) C. Zero-One 数学

    C. Zero-One 题目连接: http://codeforces.com/contest/135/problem/C Description Little Petya very much lik ...

  3. Codeforces Beta Round #97 (Div. 1) B. Rectangle and Square 暴力

    B. Rectangle and Square 题目连接: http://codeforces.com/contest/135/problem/B Description Little Petya v ...

  4. Codeforces Beta Round #97 (Div. 1)

    B 判矩阵的时候 出了点错 根据点积判垂直 叉积判平行 面积不能为0 #include <iostream> #include<cstdio> #include<cstr ...

  5. Codeforces Beta Round #97 (Div. 2)

    A题求给出映射的反射,水题 #include <cstdio> int x,ans[105],n; int main(){ scanf("%d",&n); fo ...

  6. Codeforces Beta Round #10 A. Power Consumption Calculation 水题

    A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description To ...

  7. Codeforces Beta Round #7 A. Kalevitch and Chess 水题

    A. Kalevitch and Chess 题目连接: http://www.codeforces.com/contest/7/problem/A Description A famous Berl ...

  8. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  9. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

随机推荐

  1. DevExpress 行事历(Scheduler)的常用属性、事件和方法

    一.TcxScheduler[TcxScheduler常用属性]1.Storage    - 邦定一个Storage为Scheduler显示提供数据 2.DateNavigate.ColCount   ...

  2. asp.net mvc发送邮件

    参考文献: 第一篇:http://www.cnblogs.com/qinpengming/archive/2011/06/08/2075040.html 第二篇:http://www.cnblogs. ...

  3. Extjs 基础篇—— Function 能在定义时就能执行的方法的写法 function(){...}()

    Ext.js 中 Function能在定义时就能执行的方法的写法 function(){...}() /** * 第二部分Function:能在定义时就能执行的方法的写法 function(){... ...

  4. SQLServer系统变量使用

    1.@@IDENTITY返回最后插入的标识值.这个变量很有用,当你插入一行数据时,想同时获得该行的的ID(标示列),就可以用@@IDENTITY示例:下面的示例向带有标识列的表中插入一行,并用 @@I ...

  5. python 多线程删除MySQL表

    一.需求分析 在<python 统计MySQL表信息>这篇博客中,链接如下: https://www.cnblogs.com/xiao987334176/p/9901692.html 已经 ...

  6. gtk+学习笔记(五)

    今天继续做的是昨天那个界面对的优化,直接贴下代码, void click_radio(GtkWidget *widget,gpointer *data) { 3 GtkWidget *dialog; ...

  7. java解析Xml格式的字符串

    最近在工作中,需要调别的接口,接口返回的是一个字符串,而且内容是xml格式的,结果在解析json的时候报错,最终修改了接口的返回方式,以Map返回, 才得以接收到这个xml的字符串,然后通过dom4j ...

  8. Storm(一)Storm的简介与相关概念

    一.Storm的简介 官网地址:http://storm.apache.org/ Storm是一个免费开源.分布式.高容错的实时计算系统.Storm令持续不断的流计算变得容易,弥补了Hadoop批处理 ...

  9. ASP.NET:MVC中文件上传与地址变化处理

    目录 文件的上传和路径处理必须解决下面列出的实际问题: 1.重复文件处理 2.单独文件上传 3.编辑器中文件上传 4.处理文章中的图片路径 5.处理上传地址的变化 一.上传文件和重复文件处理 文件处理 ...

  10. 基于Bootstrap的Asp.net Mvc 分页的实现

    最近写了一个mvc 的 分页,样式是基于 bootstrap 的 ,提供查询条件,不过可以自己写样式根据个人的喜好,以此分享一下.首先新建一个Mvc 项目,既然是分页就需要一些数据,我这边是模拟了一些 ...