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. nginx配置location总结及rewrite规则写法【转】

    转自 nginx配置location总结及rewrite规则写法 | Sean's Noteshttp://seanlook.com/2015/05/17/nginx-location-rewrite ...

  2. 从一份配置清单详解 Nginx 服务器配置

      概述 在前面< Nginx 服务器开箱体验> 一文中我们从开箱到体验,感受了一下 Nginx 服务器的魅力.Nginx 是轻量级的高性能 Web 服务器,提供了诸如 HTTP 代理和反 ...

  3. Vue项目之IE下打开页面是空白

    原因是:Babel 默认只转换新的 JavaScript 句法(syntax),而不转换新的 API ,比如 Iterator.Generator.Set.Maps.Proxy.Reflect.Sym ...

  4. java基础40 可变参数、自动装箱和自动拆箱

    一.可变参数 可变参数是jdk1.5新特性 1.1.可变参数的格式 数据类型...变量名 // 数据类型...变量名public static void sum(int...arr){ } 1.2.可 ...

  5. 汇编看C函数调用

    http://blog.csdn.net/wishfly/article/details/5022008   简单的函数调用,通过简单的函数调用反汇编可以清楚了解如下 1.栈到底是什么,如何操纵栈的? ...

  6. ZooKeeper的基本概念(二)

    第一篇博文,我们对Zookeeper有了一个简单的认识,而且比较浅显,易懂,这篇博文,我们了解它的基本概念,如下图所示: 了解它的基本概念,有助于我们后面的学习,虽然今天的文章都是概念性质的内容,但是 ...

  7. 如何在VS2013创建WebService并在IIS中发布

    第一步:打开VS2013,选择文件->新建->项目. 第二步:选择[ASP.net 空web应用程序],将其命名为自己想的工程名称. 第三步:然后右键点击工程,添加->web服务.然 ...

  8. Effective STL 学习笔记 31:排序算法

    Effective STL 学习笔记 31:排序算法 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...

  9. Atom编辑器试用(Win7)

     看到Atom的官网(https://atom.io/)上说,Atom是A hackable text editor for the 21st Century,是一个基于V8引擎的editor,于是决 ...

  10. mysql热数据加载管理

    5.6版本之后,提供了一个新特性来快速预热buffer_pool缓冲池.在my.cnf里面加入几个参数: innodb_buffer_pool_dump_at_shutdown = 1   --在关闭 ...