codeforces 97 div2 C.Replacement 水题
2 seconds
256 megabytes
standard input
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.
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.
Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.
5
1 2 3 4 5
1 1 2 3 4
5
2 3 4 5 6
1 2 3 4 5
3
2 2 2
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[];
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
for(i=;i<x;i++)
scanf("%d",&a[i]);
sort(a,a+x);
if(a[x-]!=)
a[x-]=;
else
a[x-]=;
sort(a,a+x);
for(i=;i<x;i++)
printf("%d ",a[i]);
return ;
}
codeforces 97 div2 C.Replacement 水题的更多相关文章
- codeforces 98 div2 C.History 水题
C. History time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- codeforces 710A A. King Moves(水题)
题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...
- codeforces 659A A. Round House(水题)
题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- 第k最短路A*启发式搜索
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 21549 Accepted: 5862 ...
- [Gradle] 输出构建 APK 的版本名到文件
android { // 输出版本名到 build 目录下的 version_name.txt 文件 applicationVariants.all { variant -> project.t ...
- 04Add.ashx(新增班级)
04Add.html <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <hea ...
- 精通linux设备驱动开发 笔记
3.2.7 错误处理 #include <linux/err.h> char * collect_data(char *userbuffer) { char *buffer; /* ...
- Allocation Sinking Optimization
LuaJIT Sponsorship Program http://luajit.org/sponsors.html Sponsorship for allocation/store sinking ...
- HotSpot VM
1.4.2 Sun HotSpot VM_深入理解Java虚拟机:JVM高级特性与最佳实践(第2版)_红黑联盟读书频道 http://book.2cto.com/201306/25434.html 提 ...
- 以太坊api访问,区块同步监测
以太坊geth api访问,区块同步监测 curl查询geth区块高度 supervisor管理以太坊geth进程 geth进程健康检查 # curl访问geth api #使用curl访问geth ...
- Design Pattern in Simple Examples
Instead of defining what is design pattern lets define what we mean by design and what we mean by pa ...
- Python小功能汇总
1.没有文件夹就新建 适用以下3种情况. (1)文件夹适用 (2)相对路径适用 (3)绝对路径适用 # 判断输出文件夹是否存在.不存在就创建 # 1.output_dir为绝对路径 if os.pat ...
- blockchain 区块链的开发,基于python或node js
现在很多人用node js做区块链的开发,因为点对点并发是区块链中的难点技术之一,而node js天然的对并发支持比较好,因此比较有优势. http://ecomunsing.com/build-yo ...