Codeforces Round #502 C. The Phone Number(构造)

地址:http://codeforces.com/contest/1017/problem/C
我原先的想法是(n / 2)取上界 + 2
但是好像 n / √n 取上界 + √n 的值更小
n / 2取上界+2,就是最长上升子序列长度为(n / 2)取上界,最长下降子序列为2
像16,15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2
答案为10
n / √n 取上界 + √n,就是最长上升子序列长度为(n / √n )取上界,最长下降子序列为√n
像16,4 3 2 1 8 7 6 5 12 11 10 9 16 15 14 13
答案为8

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 100005;
int a[N];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
       int b = sqrt(n);
       for(int i = b;i < n + b;i += b)
       {
           for(int j = min(n,i);j >= i - b + 1;--j)
                printf("%d ",j);
       }
       printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36386435/article/details/81536981