题解

144 条题解

  • 0
    @ 2009-07-16 10:27:57

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    1次AC

  • 0
    @ 2009-07-08 15:10:39

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    program zk;

    var

    shu:array [1..30] of boolean;

    a,b,c,d,i,j,m,n,no:longint;

    g:array [0..30] of int64;

    begin

    readln(n,m);

    m:=m-1;

    fillchar(shu,sizeof(shu),true);

    g[0]:=1; no:=n-1;

    for i:=1 to n do

    g[i]:=g*i;

    c:=0;

    for i:=1 to n do

    begin

    d:=0; a:=0;

    repeat

    a:=a+1;

    if shu[a]=true then d:=d+1;

    until d=m div g[no]+1;

    write(a,' ');

    shu[a]:=false;

    m:=m mod g[no];

    no:=no-1;

    end;

    end.

  • 0
    @ 2009-06-14 14:07:47

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    Too easy! 一次秒杀

  • 0
    @ 2009-06-09 22:09:20

    program qpl69;

    var

    m,n,s:integer;

    aa,bb:array[1..50] of integer;

    procedure try(a:integer);

    var

    i:integer;

    begin

    if a>n then

    begin

    s:=s+1;

    if s=m then

    begin

    for i:=1 to n do

    write(aa[i],' ');

    halt;

    end;

    end

    else

    begin

    for i:=1 to n do

    if a=1 then

    begin

    aa[a]:=i;

    bb[i]:=1;

    try(a+1);

    bb[i]:=0;

    end

    else

    begin

    if bb[i]=0 then

    begin

    aa[a]:=i;

    bb[i]:=1;

    try(a+1);

    bb[i]:=0;

    end;

    end;

    end;

    end;

    begin

    read(n,m);

    s:=0;

    try(1);

    end.

    请大家看看什么问题

    在测试时没超时,答案错了。

    因为不知道测试数据,所以不知道怎么改。

    大侠们帮下啊~~

  • 0
    @ 2009-05-29 10:47:55

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    program p1092;

    const a:array[1..21] of byte=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,0);

    var n,m,j,b,v,c:int64; i:integer;

    q:int64;

    function cheng(ewe:int64) :int64;

    begin q:=1;

    if ewe=0 then cheng:=1

    else

    begin

    for i:=1 to ewe do

    q:=q*i;

    cheng:=q;

    end; end;

    procedure pailie(var x,y:int64);

    begin

    if y>1 then

    begin

    q:=cheng(y-1);

    b:=x mod q;

    if b=0 then

    begin

    c:=x div q;

    write(a[c],' ');

    for i:=c to 20 do

    a[i]:=a;

    for i:= y-1 downto 1 do

    write(a[i],' ')

    end

    else

    begin

    c:=(x div q)+1;

    write(a[c],' ');

    for i:=c to 20 do

    a[i]:=a;

    dec(y);

    x:=x mod q ; pailie(x,y); end; end;

    end;

    begin

    read(n,m);

    pailie(m,n);end.

    小弟不才,看不懂康托展开,但自己摸索出一个递推关系式,各位非大牛有兴趣可以看看。

  • 0
    @ 2009-05-14 21:29:19

    本题不能爆搜,剪枝也超时.必须使用数学方法.

    按照全排列数(n!)作为除数进行计算, 商为升值(即在原先顺序排列基础上需要增加多少, 1235xxx, 为增加1), 余数作为被除数递归运算,直到余数为零, 同时处理位也从第一位开始往后扫描.

    对于余数为零时,对剩余的数进行逆序输出.注意逆序输出时应将商减一(即一个序列的顺序到逆序是一个全排列数)

    注意使用哈希表来表示该数是否被使用.

  • 0
    @ 2009-05-13 22:40:11

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    终于AC了,康拓展开!

  • 0
    @ 2009-05-12 10:08:41

    超短代码,为VIJOS省点KB!!!!!!!!!!!!

    纯数学问题,不过要注意细节!!!!!!!!!!!!

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var i,j,n:byte;

    k,m:int64;

    a:array[1..20] of byte;

    c:array[2..20] of int64;

    begin

    readln(n,m);

    c[2]:=1;

    for i:=2 to n-1 do

    c:=c[i]*i;

    for i:=1 to n do a[i]:=i;

    for i:=n downto 2 do begin

    k:=(m-1) div c[i]+1;

    m:=m-(k-1)*c[i];

    write(a[k],' ');

    for j:=k to i-1 do

    a[j]:=a[j+1];

    end;

    write(a[1]);

    end.

  • 0
    @ 2009-04-29 23:37:17

    交了5次,汗,结果发现是没有fillchar。。。。。

    纯数学方法,排列组合基础知识,请广大用户放心使用.....

    ---|---|---|---|---|---|---|---|---|---|

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var n:int64;m:longint;

    ans:array[0..20]of longint;

    wll:array[0..20]of int64;

    procedure init;

    var i:longint;

    begin

    readln(m,n);

    wll[0]:=1;

    wll[1]:=1;

    for i:=2 to m do

    begin

    wll[i]:=i*wll;

    end;

    end;

    procedure find;

    var k,time,q,now:int64;i,j:longint;

    v:array[0..20]of boolean;

    begin

    fillchar(v,sizeof(v),0);

    for i:=m downto 1 do

    begin

    k:=wll;

    time:=0;

    now:=0;

    while now

  • 0
    @ 2009-04-28 20:23:23

    program vijos_nimo;

    var

    n,m:int64;

    i,j,t:integer;

    jc:array[0..20] of int64;

    num:array[0..20] of integer;

    first:boolean;

    begin

    assign(input,'pailie.in');

    reset(input);

    assign(output,'pailei.out');

    rewrite(output);

    first:=true;

    readln(n,m);

    for i:=0 to n-1 do

    num[i]:=i+1;

    jc[0]:=1;

    jc[1]:=1;

    for i:=2 to n-1 do

    jc[i]:=jc*i;

    for i:=1 to n do

    begin

    t:=(m-1) div jc[n-i];

    if first then

    begin

    first:=false;

    write(num[t]);

    end

    else

    write(' ',num[t]);

    for j:=t to n-i do

    num[j]:=num[j+1];

    m:=((m-1) mod jc[n-i])+1;

    end;

    writeln;

    close(input);

    close(output);

    end.

    神奇的算法,谁能告诉我什么意思啊,我问了别人啊

  • 0
    @ 2009-04-19 16:12:07

    深搜的话超时3个

    我们不妨举个例子(给像我一样的菜鸟提示下,大牛免看)

    4的全排列

    1 2 3 4

    1 2 4 3

    1 3 2 4

    1 3 4 2

    1 4 2 3

    1 4 3 2

    2 1 3 4

    2 1 4 3

    2 3 1 4

    2 3 4 1

    2 4 1 3

    2 4 3 1

    3 1 2 4

    3 1 4 2

    3 2 1 4

    3 2 4 1

    3 4 1 2

    3 4 2 1

    4 1 2 3

    4 1 3 2

    4 2 1 3

    4 2 3 1

    4 3 1 2

    4 3 2 1

    注意到第一个数字不同的可以分成4组 每组有3!(阶乘)种排列

    再细分:刚才分的4组中 每组第二位相同的有2!种……以此类推

    ——这就是规律之一

    注意 n!可以是很大的:20!=2432902008176640000自己看着办

    另外 请大牛讲下康托展开

  • 0
    @ 2009-04-10 08:23:36

    var

    a:packed array[1..10000] of integer;vis:packed array[1..10000] of boolean;n,m,s:longint;

    procedure print;

    var i:longint;

    begin

    for i:=1 to n-1 do write(a[i],' ');

    writeln(a[n]);

    end;

    procedure search(depth:longint);

    var i:longint;

    begin

    if depth>n then begin s:=s+1;if s=m then begin print;halt;end;exit;end;

    for i:=1 to n do

    if not vis[i] then begin

    a[depth]:=i;

    vis[i]:=true;

    search(depth+1);

    vis[i]:=false;end;

    end;

    begin

    s:=0;fillchar(vis,sizeof(vis),false);readln(n,m);search(1);

    end.

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:运行超时...

    ├ 测试数据 06:运行超时...

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:运行超时...

    ---|---|---|---|---|---|---|---|-

    Unaccepted 有效得分:62 有效耗时:0ms

    各位大牛,请看一下,为什么会超时呢?????

  • 0
    @ 2009-03-28 17:10:43

    program p1092;

    var i,j:longint;

       k,m,n,t,d:int64;

       a:array[0..21] of int64;

       f:array[0..21] of integer;

    begin

    readln(n,m);

    a[0]:=1;

    for i:=1 to n do a[i]:=a*i;

    k:=n+1;

    repeat

    dec(k);

    d:=a[k-1];

    t:=(m-1) div d+1;

    m:=(m-1)mod d+1;

    i:=0; j:=0;

    repeat

    inc(i);

    if f[i]=0 then inc(j);

    until j=t;

    write(i,' ');

    f[i]:=1;

    until k=3;

    i:=0; j:=0;

    repeat

    inc(i);

    if f[i]=0 then inc(j);

    until j=m;

    write(i,' ');

    f[i]:=1;

    i:=0; j:=0;

    repeat

    inc(i);

    if f[i]=0 then inc(j);

    until j=1;

    write(i,' ');

    f[i]:=1;

    end.

  • 0
    @ 2009-02-26 19:35:41

    program p1092;

    var

    nn,n,i,j,k:longint;

    m:int64;

    f:array[1..20] of int64;

    a,b:array[1..20] of integer;

    p:array[1..20] of boolean;

    begin

    readln(nn,m);

    n:=nn;

    f[1]:=1;

    fillchar(p,sizeof(p),1);

    for i:=2 to n-1 do

    f[i]:=f*i;

    for i:=1 to n do

    b[i]:=i;

    for i:=1 to n-1 do

    begin

    k:=(m-1) div f[nn-i]+1;

    m:=(m-1) mod f[nn-i]+1;

    a[i]:=b[k];

    p[a[i]]:=false;

    for j:=k to n-1 do

      b[j]:=b[j+1];

    n:=n-1;

    end;

    for i:=1 to nn-1 do

    write(a[i],' ');

    for i:=1 to nn do

    if p[i] then writeln(i);

    end.

  • 0
    @ 2009-02-06 21:10:16

    这题什么意思??

    比如说

    3 1(1~3 这3个自然数的第一种排列)

    排列如下

    1 2 3

    1 3 2

    2 1 3

    2 3 1

    3 1 2

    3 2 1

    所以第一种排列就是1 2 3

    这道题其实有规律的

    规律? 你把1-4的全排列写一遍 自己找一下吧

    1 2 3 4

    1 2 4 3

    1 3 2 4

    1 3 4 2

    .......

    2 1 3 4

    2 1 4 3

    .......

    .......

    我的程序如下:

    program p1092;

    var i,j:longint;

    k,m,n,t,d:int64;

    a:array[0..21] of int64;

    f:array[0..21] of integer;

    begin

    readln(n,m);

    a[0]:=1;

    for i:=1 to n do a[i]:=a*i;

    k:=n+1;

    repeat

    dec(k);

    d:=a[k-1];

    t:=(m-1) div d+1;

    m:=(m-1)mod d+1;

    i:=0; j:=0;

    repeat

    inc(i);

    if f[i]=0 then inc(j);

    until j=t;

    write(i,' ');

    f[i]:=1;

    until k=3;

    i:=0; j:=0;

    repeat

    inc(i);

    if f[i]=0 then inc(j);

    until j=m;

    write(i,' ');

    f[i]:=1;

    i:=0; j:=0;

    repeat

    inc(i);

    if f[i]=0 then inc(j);

    until j=1;

    write(i,' ');

    f[i]:=1;

    end.

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-02-06 20:45:55

    问:这题是什么意思啊?

  • 0
    @ 2009-02-03 09:14:50

    成功了·

    #include

    int a[21],n;

    long long b[21],m;

    void f(int flag)

    {

    int i,j;

    long long x,y;

    for(i=1;i

  • 0
    @ 2009-05-15 16:59:30

    结合康托展开

    Program p1092;

    var

    nn,n,i,j,k:longint;

    m:int64;

    f:array[1..20] of int64;

    a,b:array[1..20] of integer;

    p:array[1..20] of boolean;

    begin

    readln(nn,m);

    n:=nn;

    f[1]:=1;

    fillchar(p,sizeof(p),1);

    for i:=2 to n-1 do

    f[i]:=f*i;

    for i:=1 to n do

    b[i]:=i;

    for i:=1 to n-1 do

    begin

    k:=(m-1) div f[nn-i]+1;

    m:=(m-1) mod f[nn-i]+1;

    a[i]:=b[k];

    p[a[i]]:=false;

    for j:=k to n-1 do

    b[j]:=b[j+1];

    n:=n-1;

    end;

    for i:=1 to nn-1 do

    write(a[i],' ');

    for i:=1 to nn do

    if p[i] then writeln(i);

    end.

  • 0
    @ 2008-12-16 21:21:30

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:运行超时...

    ├ 测试数据 06:运行超时...

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:运行超时...

    请教大牛,怎么会超时........

  • 0
    @ 2008-11-13 18:54:59

    var a:array[1..10000] of longint;

    n,max:longint;

    m,t,i,k,p,j,z:longint;

    procedure input;

    var i:integer;

    begin

    readln(m);

    readln(n);

    for i:= 1 to m do

    a[i]:=i;

    end;

    begin

    input;

    for t:= 1 to n do

    begin

    i:=m;

    while ((a[i] < a) and (i >= 2)) do

    dec(i);

    max:= m;

    for k:= i to m do

    if ((a[k] > a) and (a[k] < max)) then max:=a[k] ;

    for k:= i-1 to m-1 do

    for p:= k+1 to m do

    if a[k] > a[p] then begin z:=a[k] ; a[k] := a[p] ; a[p] := z ;end;

    j:= i -1 ;

    while a[j] max do

    inc(j);

    for k:= j downto i-1 do

    a[k]:=a[k-1];

    a:=max;

    end;

    for k:= 1 to m do

    write(a[k]:2);

    readln;

    readln;

    end.

    这个算法过那个火星人手指的就过了...怎么搞的..只对了1个

信息

ID
1092
难度
5
分类
组合数学 点击显示
标签
(无)
递交数
4512
已通过
1398
通过率
31%
被复制
11
上传者