nyoj 139 我排第幾個 數學 康托展開

2021-07-10 17:30:01 字數 1220 閱讀 7957

時間限制:

1000 ms  |  記憶體限制:

65535 kb

難度:3 描述

現在有"abcdefghijkl」12個字元,將其所有的排列中按字典序排列,給出任意一種排列,說出這個排列在所有的排列中是第幾小的?

輸入

第一行有乙個整數n(0

輸出輸出乙個整數m,佔一行,m表示排列是第幾位;

樣例輸入

3

abcdefghijkl

hgebkflacdji

gfkedhjblcia

樣例輸出

1

302715242

260726926

康托展開

康托展開是乙個雙射,即不僅可以求是第幾小,而且可以根據是第幾小求出該排列.

code:

#include #include #include #include #include #include #include #include #define inf 0x3f3f3f3f

#define eps 1e-8

#define si(a) scanf("%d", &a)

#define sl(a) scanf("%lld", &a)

#define sf(a) scanf("%lf", &a)

#define ss(a) scanf("%s", a)

#define pi(a) printf("%d\n", (a))

#define pf(a) printf("%.2lf\n", (a))

#define pl(a) printf("%lld\n", (a))

#define ps(a) printf("%s\n", (a))

#define w(a) while((a)--)

#define clr(a, b) memset(a, (b), sizeof(a))

#define ll long long

#define pi acos(-1.0)

const int m = 12;

int main()

char s[m+1];

int t; si(t);

w(t)

ans += sum * f[len-i-1];

}pl(ans+1);

}return 0;

}

nyoj 139 我排第幾個(康托展開)

時間限制 1000 ms 記憶體限制 65535 kb 難度 3 描述 現在有 abcdefghijkl 12個字元,將其所有的排列中按字典序排列,給出任意一種排列,說出這個排列在所有的排列中是第幾小的?輸入 第一行有乙個整數n 0 輸出輸出乙個整數m,佔一行,m表示排列是第幾位 樣例輸入 3 ab...

nyoj139 我排第幾個(康拓展開)

時間限制 1000 ms 記憶體限制 65535 kb 難度 3描述 現在有 abcdefghijkl 12個字元,將其所有的排列中按字典序排列,給出任意一種排列,說出這個排列在所有的排列中是第幾小的?輸入 第一行有乙個整數n 0 輸出輸出乙個整數m,佔一行,m表示排列是第幾位 樣例輸入 3 abc...

NYOJ 139 我排第幾個(康托展開)

時間限制 1000 ms 記憶體限制 65535 kb 難度 3 描述現在有 abcdefghijkl 12個字元,將其所有的排列中按字典序排列,給出任意一種排列,說出這個排列在所有的排列中是第幾小的?輸入第一行有乙個整數n 0 輸出輸出乙個整數m,佔一行,m表示排列是第幾位 樣例輸入 3 abcd...