144 条题解
-
0i8 LV 8 @ 2009-10-18 11:57:59
program p1092;
VAR
i,j,n,m,k,s,p:longint;
c:array[0..100]of 0..1;
f:array[1..100]of int64;begin
readln(n,m);fillchar(c,sizeof(c),1);
f[1]:=1; c[0]:=0;
for i:=2 to n do f[i]:=f*i;p:=n;
repeat
dec(p);
k:=m div f[p];
m:=m mod f[p];i:=0;s:=0;
while s0 then inc(i);
while c[i]=0 do inc(i);
c[i]:=0;
write(i,' ');until m=0;
for i:=n downto 1 do
if c[i]=1 then write(i,' ');
writeln;
end. -
02009-10-17 09:58:44@
能不能把康拓排序倒过来写!?
-
02009-10-11 16:21:16@
额 还以为是全排列呢.....
-
02009-09-27 11:06:39@
program p1092;
var
m,s,mm:double;
n,i,j,t,k:longint;
a:array[1..30] of integer;
f:array[1..30] of boolean;
begin
read(n,m);
m:=trunc(m-1);
for i:=n-1 downto 1 do
begin
mm:=m; s:=1;
for j:=i downto 2 do begin s:=s*j; mm:=trunc(mm) div j; end;
a[i]:=trunc(mm);
m:=trunc(m-trunc(mm)*s);
end;
fillchar(f,sizeof(f),true);
for i:=n-1 downto 1 do
begin
t:=0; k:=0;
while (t -
02009-09-23 20:03:31@
为什么会超时啊??
Var
a,b,p:array[0..20]of integer;
i,j,n,m:longint;
Begin
readln(n,m);
for i:=0 to n-1 do b[i]:=0;
for j:=1 to m-1 do
begin
b[0]:=b[0]+1;
i:=0;
while b[i]>i do
begin
b[i]:=0;
b:=b+1;
i:=i+1;
end;
end;
for i:=0 to n-1 do a[i]:=i+1;for i:=n-1 downto 0 do
begin
p[i]:=a[b[i]];
for j:=b[i] to i-1 do a[j]:=a[j+1];
end;
for i:=n-1 downto 0 do
begin
write(p[i]);
if i0 then write(' ');
end;
readln;
End. -
02009-09-20 08:31:16@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms -
02009-09-15 20:58:36@
#include
using namespace std;
__int64 d[30];
int f[30];
int t1,n,j,i;
__int64 k;
int main(){
cin>>n>>k;
for(i=1;i=1;i--){d[i]=d*(n-i+1);}
for(i=1;i -
02009-08-25 09:16:26@
var
a:array[1..21]of int64;
b:array[1..20]of integer;
i,j,n:longint;
m,k:int64;
begin
readln(n,m);
m:=m-1;
a[1]:=1;
b[1]:=1;
for i:= 2 to n do
begin
a[i]:=a*i;
b[i]:=i;
end;
for i:=n downto 2 do
begin
k:=m div a;
m:=m mod a;
write(b[k+1],' ');
for j:=k+1 to n-1 do
b[j]:=b[j+1];
end;
writeln(b[1]);
end. -
02009-08-18 23:25:36@
开一个阶乘数组 然后构造
-
02009-08-14 10:38:33@
program p_1;
var
a:array[1..21]of int64;
b:array[1..20]of integer;
i,j,n:longint;
m,k:int64;
begin
readln(n,m);
m:=m-1;
a[1]:=1;
b[1]:=1;
for i:= 2 to n do
begin
a[i]:=a*i;
b[i]:=i;
end;
for i:=n downto 2 do
begin
k:=m div a;
m:=m mod a;
write(b[k+1],' ');
for j:=k+1 to n-1 do
b[j]:=b[j+1];
end;
writeln(b[1]);
end. -
02009-08-13 21:28:01@
傻傻地用全排列算法慢慢找,超时.......
原来是数论的题目....... -
02009-08-13 15:43:41@
超短代码....晒一下
var
a:array[1..21]of int64;
b:array[1..20]of integer;
i,j,n:longint;
m,k:int64;
begin
readln(n,m);
m:=m-1;
a[1]:=1;
b[1]:=1;
for i:= 2 to n do
begin
a[i]:=a*i;
b[i]:=i;
end;
for i:=n downto 2 do
begin
k:=m div a;
m:=m mod a;
write(b[k+1],' ');
for j:=k+1 to n-1 do
b[j]:=b[j+1];
end;
writeln(b[1]);
end. -
02009-08-07 22:05:28@
C似乎装不了20!那么大的数……不过似乎没有那么大的数据?
设一个数组mark[i]记录i有没有被用过
从第一位开始循环 i是第几位
k=(m-1)/jc(n-i)+1 从mark中从前往后找到第k个没用过的数 输出 他就是第i位上的数
m=m%jc(n-i)
如果发现m=0就说明余下的n-i个数都是倒序排列的 直接输出 结束 就可以了 -
02009-08-05 15:34:47@
var
n,i,j,k,t:longint;
m:int64;
a:array[1..20] of longint;
s:set of 1..20;
function calc(x:longint):int64;
var i:longint;
ans:int64;
begin
ans:=1;
for i:=1 to x do ans:=ans*i;
exit(ans);
end;
Begin
readln(n,m);
s:=[];
for i:=1 to n do s:=s+[i];
m:=m-1;
for i:=1 to n do
begin
for j:=n downto 1 do
if j in s then begin
t:=0;
for k:=1 to j-1 do if k in s then inc(t);
if t*calc(n-i)>m then continue;
s:=s-[j];
a[i]:=j;
m:=m-t*calc(n-i);
break;
end;
end;
for i:=1 to n do write(a[i],' ');
end. -
02009-08-03 20:10:29@
var
n :longint;
fac :array[0..20]of int64;
v :array[0..20]of boolean;
m :int64;
k,s :longint;
i,j :longint;
begin
readln(n,m);
fac[0]:=1;
for i:=1 to n do
fac[i]:=fac*i;
fillchar(v,sizeof(v),true);
for i:=n downto 1 do begin
j:=1;
while j*fac -
02009-08-03 17:40:24@
作个康托展开
const jc:array[1..20] of int64=
(
1,
2,
6,
24,
120,
720,
5040,
40320,
362880,
3628800,
39916800,
479001600,
6227020800,
87188291200,
1307674368000,
20922789888000,
355687428096000,
6402373705728000,
121645100408832000,
2432902008176640000
);// jc[] 为阶乘表
var a:array[1..20] of integer;
n,b,c:longint;
p,m:int64;
list:array[1..20] of boolean;function l(num:integer):integer;
var p:integer;
begin
for p:=1 to n do
begin
if list[p]=false then dec(num);
if num=0 then break;
end;
l:=p;
list[l]:=true;
end;begin
fillchar(list,sizeof(list),false);
readln(n,m);
p:=1;
m:=m-1;
while p -
02009-08-03 10:58:05@
哎,想不A都不行,什么世道。。。。。。
var
used:array [1..20] of boolean;
a:array [1..20] of integer;
m:int64;
n:longint;
s,st:string;
procedure solve(dep:integer);
var
flag:boolean;
i,j,k:longint;
t:int64;
begin
flag:=true;
if dep>n then
begin
for i:=1 to (n-1) do
write(a[i],' ');
writeln(a[n]);
flag:=false;
end;
if flag then
begin
t:=1;
for i:=2 to (n-dep) do
t:=t*i;
if m mod t=0 then
j:=m div t
else
j:=m div t+1;
k:=0;
for i:=1 to n do
if not used[i] then
begin
inc(k);
if k=j then
begin
a[dep]:=i;
used[i]:=true;
break
end;
end;
m:=m mod t;
if m=0 then
m:=t;
solve(dep+1);
end;
end;
begin
readln(st);
s:=copy(st,1,pos(' ',st)-1);
st:=copy(st,pos(' ',st)+1,length(st));
val(s,n);
val(st,m);
fillchar(used,sizeof(used),false);
solve(1);
end. -
02009-08-02 22:03:09@
前面的大牛似乎程序都很长。。。。。。。
来一个短的^_^(一次AC。。。)
======================晒程序=====================
var
d:array[0..30] of int64;
f:array[0..30] of integer;
t1,n,j,i:LONGINT;
k:int64;
begin
readln(n,k);
for i:=1 to n do f[i]:=i;
d[n]:=1;d[n+1]:=1;
for i:=n-1 downto 1 do d[i]:=d*(n-i+1);
for i:=1 to n do begin
t1:=((k-1) div d)+1;
k:=((k-1)mod d)+1;
write(f[t1],' ');
for j:=t1 to n-i+1 do f[j]:=f[j+1];
end;
writeln();
end.Accepted 有效得分:100 有效耗时:0ms
大概O(N)吧。。。。
^_^ -
02009-07-19 15:46:29@
终于真正地能一次AC了……
用构造解,基本做出来就不会超时了。还有考虑边界。 -
02009-07-16 14:37:06@
program dsa;
var a:array[1..20]of longint;
i,j:longint;
bb,n,k:int64;
m:qword;
begin
readln(n,m);
bb:=1;
for i:=2 to n-1 do bb:=bb*i;
for i:=1 to n do a[i]:=i;
i:=1;
if m=1 then
begin
for j:=1 to n do write(a[j],' ');
exit;
end;
while i0 do
begin
m:=m-bb;
inc(k);
end;
write(a[k],' ');
for j:=k to n-1 do a[j]:=a[j+1];
bb:=bb div (n-i);
inc(i);
end;
end.农夫山泉