生气,比赛时就做出两道。

A题,手速题,数组从属关系。

B题,手速题,模拟三进制。

C题,手速题,但我感觉明明就是阅读题,读明白了就能瞬秒,英语拙疾。

1.what minimum number could occupy it after the replacement and the sorting.

2.Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.

这两句鸟语下午饿着肚子硬读了好几遍,也没读明白,真挫。

#include <iostream>
#include <algorithm>
using namespace std;
struct P{
    int i,k;
}p[100005];
int cmpk(P x,P y){
    return x.k<y.k;
}
int main(){
    int n;
    while(cin >> n){
        bool flag=0;
        for(int i=0;i<n;i++){
            cin >> p[i].k;
            p[i].i=i;
            if(p[i].k!=1) flag=1;
        }
        if(!flag){
            for(int i=0;i<n;i++){
                if(i==n-1) cout << p[i].k+1 <<endl;
                else cout << p[i].k <<" ";
            }
            continue;
        }
        sort(p,p+n,cmpk);
        for(int i=n;i>=1;i--){
            p[i].k=p[i-1].k;
        }
        p[0].k=1;
        for(int i=0;i<n;i++){
            if(i==n-1) cout << p[i].k <<endl;
            else cout << p[i].k<<" ";
        }
    }

    return 0;
}

 

1.输入,判断是否全为1,如果是最后一个元素+1,数组输出。

2.不全为1,将数组元素整体向后移一位,第一个元素为1,数组输