HDU 6628 permutation 1(暴力)

HDU 6628 permutation 1(暴力)

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6628

我的博客:http://acmerszq.cn

题意:

​ 找第k小的字典序的差分数列的原序列。

思路:

​ 赛后才写完代码,比赛中太憨憨,经队友川神提醒数据只用求到10000才醒悟(其实还想了下,然后这是他的博客 https://blog.csdn.net/ayyyyy_zc?utm_source=feed )。本来这种题目真的不想发,还是为了防止自己的??行为再犯,还是记录下吧。rt,暴力存即可。按题解用dfs爆搜做代码很短。

AC代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int SIZE = 1e5 + 5;
const int MAXN = 1e4 + 4;
struct Node {
    int len1, len2;
    char str1[10];
    char str2[10];
    Node() : len1(0), len2(0) {}
} ss[SIZE];
bool cmp(const Node& a, const Node& b) {
    return strcmp(a.str2, b.str2) <= 0;
}
char jihe[10][MAXN][10];
int tol;
int jl[10];
void solve(int n) {
    memset(ss, 0, sizeof(ss));
    tol = 0;
    char arr[10] = {'1', '2', '3', '4', '5', '6', '7', '8'};
    do {
        for (int i = 0; i < n; i++) {
            ss[tol].str1[ss[tol].len1++] = arr[i];
        }
        tol++;
    } while (next_permutation(arr, arr + n));
    for (int i = 0; i < tol; i++) {
        for (int j = 1; j < n; j++) {
            ss[i].str2[ss[i].len2++] = (ss[i].str1[j] - ss[i].str1[j - 1] + '0');
        }
    }
    sort(ss, ss + tol, cmp);
    if (n == 8) {
        for (int i = 0; i < tol; i++) {
            strcpy(jihe[8][jl[8]++], ss[i].str1);
            if(jl[8] == 10001) break;
        }
        for (int i = 0; i < tol; i++) {
            if (ss[i].str1[0] == '1') {
                strcpy(jihe[9][jl[9]++], ss[i].str1);
            }
        }
        for (int i = 0; i < tol; i++) {
            if (ss[i].str1[0] == '2') {
                strcpy(jihe[9][jl[9]++], ss[i].str1);
            }
            if (jl[9] == 10001) break;
        }
    } else {
        for(int i = 0; i < tol; i++) {
            strcpy(jihe[n][jl[n]++], ss[i].str1);
        }
    }
}
int main() {
    // freopen("RAW/in", "r", stdin);
    // freopen("RAW/out", "w", stdout);
    for(int i = 1; i <= 8; i++) {
        solve(i);
    }
    // for(int i = 0; i < jl[9]; i++) {
    //     printf("%s\n", jihe[9][i]);
    // }
    int T;
    scanf("%d", &T);
    while(T--) {
        int n;
        long long k;
        scanf("%d%lld", &n, &k);
        k = min((long long)10000, k);
        if(n > 8) {
            printf("%d", n);
            for(int i = 1; i <= n-9; i++) {
                printf(" %d", i);
            }
            for(int i = 0; i < 8; i++) {
                printf(" %d", (int)(jihe[9][k-1][i]-'0'+(n-9)));
            }
        } else {
            for(int i = 0; i < n; i++) {
                if(i > 0) printf(" ");
                printf("%c", jihe[n][k-1][i]);
            }
        }
        printf("\n");
    }
    return 0;
}
//4960th 2 8 7 3 5 4 6 1
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值