A. 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.

Sample test(s)
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
题意:给出一个长度为n的数组,要求替换掉数组中的一个数。(替换的含义是要用另外一个与次数不同的数来替换)全部的数的范围在[1,10^9],然后排序后的要求是使每一个位置上的数尽可能小,一种比較巧的做法是对于这个数组先排序(升序) 然后将最大的那个数换成1 假设最大的为1 则换成2(想想 为什么 ) 
然后在排序输出就能够了
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
#define LL long long
int a[100050];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%d",a+i);
sort(a,a+n);
a[n-1]=a[n-1]==1? 2:1;
sort(a,a+n);
for(int i=0;i<n;i++)
if(i!=n-1)
printf("%d ",a[i]);
else
printf("%d\n",a[i]);
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

Codeforces 135A-Replacement(思维)的更多相关文章

  1. CodeForces 604C 【思维水题】`

    题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...

  2. Minimum Integer CodeForces - 1101A (思维+公式)

    You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...

  3. Codeforces 1038D - Slime - [思维题][DP]

    题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...

  4. AND Graph CodeForces - 987F(思维二进制dfs)

    题意:给出n(0≤n≤22)和m,和m个数ai,1 ≤ m ≤ 2n ,0≤ai<2n ,把ai & aj == 0 的连边,求最后有几个连通块 解析:一个一个去找肯定爆,那么就要转换一 ...

  5. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  6. Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)

    Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...

  7. Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)

    Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...

  8. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

  9. Stack Sorting CodeForces - 911E (思维+单调栈思想)

    Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty) ...

随机推荐

  1. HttpClient使用具体解释

    Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,添加�了易用性和灵活性(详细差别,日后我们再讨论),它不仅是client发送Http请求变得e ...

  2. ORACLE单字符函数的函数

     1.           ASCII(C) 说明:返回C的首字符在ASCII码中相应的十进制 举例: SQL>SELECT ASCII('A') A,ASCII('a') B,ASCII( ...

  3. 重新想象 Windows 8 Store Apps (23) - 文件系统: 文本的读写, 二进制的读写, 流的读写, 最近访问列表和未来访问列表

    原文:重新想象 Windows 8 Store Apps (23) - 文件系统: 文本的读写, 二进制的读写, 流的读写, 最近访问列表和未来访问列表 [源码下载] 重新想象 Windows 8 S ...

  4. ** poj Y2K Accounting Bug 2586

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10117   Accepted: 50 ...

  5. UML 简单的总结

    上某一个地方,总有个记忆挥不散,每一个深夜某一个地方,总有着最深的思量- 都说岁月无情人有情,记忆easy催人老,可有时候反倒觉着人比岁月更无情.岁月留下了我们成长的印记,但是有时候以前认为会相伴永远 ...

  6. 【C语言探索之旅】 第二部分第一课:模块化编程

    内容简介 1.课程大纲 2.第二部分第一课: 模块化编程 3.第二部分第二课预告: 进击的指针,C语言王牌 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C ...

  7. [模拟Android微信]主界面

    首先看很像模仿: 走出来: 实现过程: 依赖类库:actionbarsherlock 用actionbarsherlock来实现顶部的搜索的效果. tab用的是Viewpaper实现的. 详细细节: ...

  8. Discuz 楼主帖子采集

    try { ; i < ; i++) { var html = GetHtmls("http://bbs.fobshanghai.com/viewthread.php?tid=3885 ...

  9. 讲座:采用Store检查邮件(1)

    讲座:采用Store检查邮件(1) 一.邮件接收的体系结构 JavaMail API中定义了一个java.mail.Store类,用于运行邮件的接收任务,该类的实例对象封装了某种邮件接收协议的底层实施 ...

  10. Android client和服务器JSP互传中国

    出于兼容性简化.传统中国等多国语言.推荐使用UTF-8编码. 首选.我们期待Android到底应该怎么办: 在发送前,应该对參数值要进行UTF-8编码,我写了一个static的 转换函数.在做发送动作 ...