Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)----C

        这个。。。玄学,先留个坑,做法就是按照sqrt(n)分块,然后块内有序,有点像分块算法。具体的原理先留个坑。

代码如下

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int main(){
    int n;
    cin >> n;
    int N = sqrt(n);
    int k = N;
    while (1) {
        a[n+k-N] = n-k+1;
        k--;
        if (k == 0) break;
    }
    for (int i=n-N; i>=1; i--) {
        a[i] = a[i+N]-N;
    }
    for (int i=n%N; i>=1; i--) {
        a[i] = ++k;
    }
    for (int i=n; i>=1; i--) {
        cout << a[i] << ' ';
    }
    cout << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/CCCCTong/article/details/81590614