CodeFoeces-285A

题目

原题链接:A. Slightly Decreasing Permutations

题意

给出n和k。要求输出长度为n(数值不超过n)且包括k个降序的序列。

代码

#include
using namespace std;
int main() {
    int n,k,s[100010];
    cin>>n>>k;
    if(n==k+1) {
        for(int i=n; i>=1; i--) {
            printf("%d",i);
            printf("%c",i==1?'\n':' ');
        }
    } else {
        int maxt=n,t=n-k;
        while(k--){
            printf("%d ",maxt--);
        }
        for(int i=1; i<=t; i++) {
            printf("%d",i);
            printf("%c",i==n?'\n':' ');
        }
    }
    return 0;
}

你可能感兴趣的:(CodeFoeces-285A)