codeforces 97 div2 C.Replacement 水题
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是坑点;
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll __int64 4 #define mod 1000000007 5 #define inf 100000000000005 6 #define MAXN 10000010 7 //#pragma comment(linker, "/STACK:102400000,102400000") 8 int a[100010]; 9 int main() 10 { 11 int x,y,z,i,t; 12 scanf("%d",&x); 13 for(i=0;i<x;i++) 14 scanf("%d",&a[i]); 15 sort(a,a+x); 16 if(a[x-1]!=1) 17 a[x-1]=1; 18 else 19 a[x-1]=2; 20 sort(a,a+x); 21 for(i=0;i<x;i++) 22 printf("%d ",a[i]); 23 return 0; 24 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· [翻译] 为什么 Tracebit 用 C# 开发
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· DeepSeek崛起:程序员“饭碗”被抢,还是职业进化新起点?
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端