题解

337 条题解

  • 0
    @ 2009-04-26 20:32:20

    各位同学呀,作者道题千万要仔细啊,最后一组数据比10000大,开数组时多开一些否则很惨的。20次AC,悲哀啊。

  • 0
    @ 2009-04-20 21:42:35

    两次AC

    编译通过...

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

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

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

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

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

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

    1E9进制高精度

    输入输出有点麻烦

    不知道为什么1E9比1E1快这么多?

    program vijos_1040; { 高精度乘法 }

    const

    maxn=20001;

    base=100;

    logBase=2;

    type

    baseType=qword;

    highInt=record

    da:array[1..maxn] of baseType;

    len:integer;

    end;

    highPoint=^highInt;

    var

    a,b,c:highInt;

    procedure empty(var a:highInt);

    begin

    with a do

    begin

    len:=1;

    fillchar(da,sizeof(da),0);

    end;

    end;

    procedure val(var s:ansistring;var a:highInt);

    var

    ch:char;

    i,j,k:integer;

    begin

    with a do

    begin

    while length(s) mod logBase0 do s:='0'+s;

    j:=0;

    k:=length(s);

    while k>0 do

    begin

    inc(j);

    for i:=k-logBase+1 to k do

    da[j]:=da[j]*10+ord(s[i])-48;

    dec(k,logBase);

    end;

    len:=j;

    end;

    end;

    procedure init;

    var

    s:ansistring;

    po,len:integer;

    begin

    empty(a);

    empty(b);

    empty(c);

    readln(s);

    val(s,a);

    readln(s);

    val(s,b);

    end;

    procedure highMul(const a,b:highInt;var c:highInt);

    var

    i,j,l:integer;

    begin

    empty(c);

    for i:=1 to a.len do

    for j:=1 to b.len do

    begin

    inc(c.da,a.da[i]*b.da[j]);

    if c.da>=base then

    begin

    inc(c.da,c.da div base);

    c.da:=c.da mod base;

    end

    end;

    l:=a.len+b.len+1;

    while (l>0) and (c.da[l]=0) do dec(l);

    c.len:=l;

    end;

    procedure print(const a:highInt);

    var

    i,j:integer;

    begin

    with a do

    for i:=len downto 1 do

    begin

    if ilen then

    for j:=1 to logBase-trunc(ln(da[i])/ln(10))-1 do

    write(0);

    write(da[i]);

    end;

    writeln;

    end;

    begin

    init;

    highMul(a,b,c);

    print(c);

    end.

  • 0
    @ 2009-04-15 23:08:23

    program p1040;

    var s:ansistring;

    a,b,ans:array[1..10000]of longint;

    m,n,i,j,k,l,r,tt:longint;

    procedure print(i:longint);

    var j,t:longint;

    begin

    if (i=k)or(ans[i] div 10000) then write(ans[i])

    else

    begin

    t:=ans[i];

    for j:=1 to 4 do

    begin

    t:=t div 10;

    if t=0 then break;

    end;

    t:=4-j;

    for j:=1 to t do write('0');

    write(ans[i]);

    end;

    end;

    begin

    readln(s);

    k:=length(s);

    m:=0;

    i:=1;

    while i

  • 0
    @ 2009-04-13 13:51:59

    楼下那位的能过吗?

  • 0
    @ 2009-04-12 16:12:30

    program P_1027;

    type

    xx=array[0..520]of longint;

    var

    a,b,c:xx;

    s:string;

    i:longint;

    function cheng(a,b:xx):xx;

    var

    i,j:longint;

    c:xx;

    begin

    fillchar(c,sizeof(c),0);

    c[0]:=a[0]+b[0];

    for i:=1 to a[0] do

    for j:=1 to b[0] do

    begin

    c:=a[i]*b[j]+c;

    c:=c div 10 +c;

    c:=c mod 10;

    end;

    while (c[0]>1)and(c[c[0]]=0) do dec(c[0]);

    cheng:=c;

    end;

    begin

    readln(s);

    a[0]:=length(s);

    for i:=1 to a[0] do

    a[i]:=ord(s[a[0]+1-i])-48;

    readln(s);

    b[0]:=length(s);

    for i:=1 to b[0] do

    b[i]:=ord(s[b[0]+1-i])-48;

    c:=cheng(a,b);

    for i:=c[0] downto 1 do

    write(c[i]);

    writeln;

    end.

  • 0
    @ 2009-04-08 20:10:58

    var

    s1,s2,s3,s:ansistring;

    i,j,k1,k2,l1,l2,t1,t2,m,x,y,z,w:longint;

    a,b,c:array[1..5000]of longint;

    begin

    readln(s1);

    l1:=length(s1);

    k1:=l1;

    t1:=1;

    while k1>=4 do

    begin

    s:=copy(s1,k1-3,4);

    val(s,m);

    a[t1]:=m;

    inc(t1);

    dec(k1,4);

    end;

    if l1 mod 40 then begin

    s:=copy(s1,1,l1 mod 4);

    val(s,m);

    a[t1]:=m;

    end

    else dec(t1);

    readln(s2);

    l2:=length(s2);

    k2:=l2;

    t2:=1;

    while k2>=4 do

    begin

    s:=copy(s2,k2-3,4);

    val(s,m);

    b[t2]:=m;

    inc(t2);

    dec(k2,4);

    end;

    if l2 mod 40 then begin

    s:=copy(s2,1,l2 mod 4);

    val(s,m);

    b[t2]:=m;

    end

    else dec(t2);

    for i:=1 to t1 do

    for j:=1 to t2 do

    begin

    x:=a[i]*b[j];

    y:=x div 10000;

    z:=x mod 10000;

    w:=i+j-1;

    c[w]:=c[w]+z;

    c[w+1]:=c[w+1]+c[w]div 10000+y;

    c[w]:=c[w] mod 10000;

    end;

    m:=t1+t2;

    if c[m]=0 then dec(m);

    write(c[m]);

    for i:=m-1 downto 1 do

    begin

    if (c[i]>=1000)and(c[i]=100)and(c[i]=10)and(c[i]=0)and(c[i]

  • 0
    @ 2009-07-09 16:21:39

    普通乘法,只是要用ansistring!水题!

  • 0
    @ 2009-04-07 17:14:31

    program chengfa;

    var str1,str2:string;

    n1,n2,i,j,n,w,p,q:integer;

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

    c:array[1..1000] of integer;

    begin

    readln(str1);readln(str2);

    n1:=length(str1);

    n2:=length(str2);

    for i:=n1 downto 1 do val(str1[i],a[n1-i+1]);

    for i:=n2 downto 1 do val(str2[i],b[n2-i+1]);

    for i:=1 to (n1+n2) do c[i]:=0;

    for i:=1 to n2 do

    for j:=1 to n1 do

    begin

    w:=i+j-1;q:=c[w];

    c[w]:=(q+(a[j]*b[i]) mod 10) mod 10;

    c[w+1]:=c[w+1]+(q+(a[j]*b[i]) mod 10) div 10+ (a[j]*b[i]) div 10;

    end;

    for i:=(n1+n2) downto 1 do

    if (c[i]0) then

    begin

    n:=i;break;

    end;

    for i:=n downto 1 do write(c[i]);

    end.

  • 0
    @ 2009-04-06 10:41:15

    var

    s1,s2,s3:ansistring;

    a,b,c,d:array[0..5000]of longint;

    i,j,k,l1,l2,la,lb,ka,kb,temp:longint;

    begin

    readln(s1);

    readln(s2);

    if length(s1)=0)and(c[j]=10)and(c[j]=100)and(c[j]

  • 0
    @ 2009-04-03 20:47:15

    TMD ~~~~~~~~`竟然会 超时~~~~~~~\ 怎么可能???????

  • 0
    @ 2009-04-02 11:28:24

    编译通过...

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

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

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

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

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

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

    program p1040;

    var

    a,b,c:array[1..20001] of longint;

    i,j,k,t,p,q:longint;

    ch:char;

    begin

    p:=0;

    while not eoln do begin

    read(ch);

    inc(p);

    a[p]:=ord(ch)-48;

    end;

    readln;

    q:=0;

    while not eoln do begin

    read(ch);

    inc(q);

    b[q]:=ord(ch)-48;

    end;

    for i:=1 to p div 2 do begin

    k:=a[i];

    a[i]:=a[p+1-i];

    a[p+1-i]:=k;

    end;

    for i:=1 to q div 2 do begin

    k:=b[i];

    b[i]:=b[q+1-i];

    b[q+1-i]:=k;

    end;

    fillchar(c,sizeof(c),0);

    for i:=1 to p do

    for j:=1 to q do

    c:=c+a[i]*b[j];

    for i:=1 to p+q do begin

    c:=c+c[i] div 10;

    c[i]:=c[i] mod 10;

    end;

    k:=20001;

    while c[k]=0 do dec(k);

    for i:=k downto 1 do

    write(c[i]);

    end.

  • 0
    @ 2009-03-28 12:48:40

    第一次写压位高精度。感觉不错

    0MS

  • 0
    @ 2009-03-22 08:44:39

    普通一位高精可以!

    编译通过...

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

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

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

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

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

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

  • 0
    @ 2009-03-21 20:11:31

    编译通过...

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

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

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

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

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

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

    第一次写压位高精,居然卡了我一下午。。。= =

    居然错在读入上了。。囧。。。

  • 0
    @ 2009-03-19 18:21:39

    var i,j,k,l1,l2,m,g,n,c,x,z:longint;

    a,b,y,jia:array[1..1000] of longint;

    s1,s2:ansistring;

    begin

    readln(s1); l1:=length(s1); n:=500;

    readln(s2); l2:=length(s2); z:=0;

    for i:=l1 downto 1 do val(s1[i],a[n+i-l1],z);

    for i:=l2 downto 1 do val(s2[i],b[n+i-l2],z);

    for i:=n downto n-l2+1 do

    begin

    g:=0;

    for j:=500 downto 1 do

    begin

    c:=a[j]*b[i]+g;

    y[j]:=c mod 10;

    g:=c div 10;

    end;

    g:=0;

    for j:=500 downto 1 do

    begin

    c:=y[j]+jia[j]+g;

    jia[j]:=c mod 10;

    g:=c div 10;

    end;

    fillchar(y,sizeof(y),0);

    z:=z+1;

    end;

    m:=1;

    while jia[m]=0 do inc(m);

    for i:=m to 500 do write(jia[i]);

    end.

    哪个地方错了~~5555

  • 0
    @ 2009-03-18 15:59:18

    要压位.

  • 0
    @ 2009-03-17 21:25:08

    交了5次才AC 太不容易了,开始数组里存一位数,最后一个数据超时,后来改成4位数…………………………

    program p1040;

    var a,b:array[-5..10000] of longint;

    c:array[-5..100000000] of longint;

    ch:ansistring;

    l1,l2,m,k:longint;

    procedure goin;

    var l,min,i,j:longint; s:string;

    begin

    readln(ch); s:='';min:=10000;

    l1:=length(ch);

    for i:=l1 downto 1 do

    begin

    if length(s)=100 then write('0',c[m]) else

    if c[m]>=10 then write('00',c[m]) else

    if c[m]>=1 then write('000',c[m]) else

    write('0000');

    end;

    writeln;

    end.

  • 0
    @ 2009-03-03 23:16:58

    编译通过...

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

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

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

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

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

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

    10000位压位,一次AC,秒杀……

    #include "stdio.h"

    #include "string.h"

    int main()

    { char a[10005],b[10005];

    int x[10005]={0},y[10005]={0},s[20015]={0},i,j,n,m,d=0,t=0,t1=0,len;

    scanf("%s%s",a,b);

    n=strlen(a);

    m=strlen(b);

    for(i=n-4;i>=0;i-=4)

    x[t++]=(a[i]-'0')*1000+(a-'0')*100+(a-'0')*10+(a-'0')*1;

    if(n-t*4==3)

    x[t]=(a[0]-'0')*100+(a[1]-'0')*10+(a[2]-'0')*1;

    else

    if(n-t*4==2)

    x[t]=(a[0]-'0')*10+(a[1]-'0')*1;

    else

    if(n-t*4==1)

    x[t]=a[0]-'0';

    for(j=m-4;j>=0;j-=4)

    y[t1++]=(b[j]-'0')*1000+(b[j+1]-'0')*100+(b[j+2]-'0')*10+(b[j+3]-'0')*1;

    if(m-t*4==3)

    y[t1]=(b[0]-'0')*100+(b[1]-'0')*10+(b[2]-'0')*1;

    else

    if(m-t*4==2)

    y[t1]=(b[0]-'0')*10+(b[1]-'0')*1;

    else

    if(m-t*4==1)

    y[t1]=b[0]-'0';

    for(i=0;i=0;i--,t1++)

    if(b[i]!=0)

    break;

    for(i=len;i>=0;i--)

    {

    if(i==len)

    printf("%d",s[i]);

    else

    printf("%.4d",s[i]);

    }

    return 0;

    }

  • 0
    @ 2009-11-13 15:32:13

    type arra=array[-3..10000]of longint;

    var a,b,c:arra;

    m,n,next,l1,l2,l3:longint;

    procedure init(var m:arra;var lo:longint);

    var k:array[-4..10000]of char;

    q:array[-3..10000]of longint;

    l,i,j,z,p:longint;

    s:string;

    begin

    l:=0;

    fillchar(m,sizeof(m),0);

    while not(eoln) do

    begin

    inc(l);

    read(k[l]);

    end;

    for i:=-4 to 0 do k[i]:='0';

    for i:=1 to (l div 3)+1 do

    begin

    s:='000';

    z:=1;

    for j:=l-i*3+1 to l-(i-1)*3 do

    begin

    s[z]:=k[j];

    inc(z);

    end;

    val(s,q[i]);

    end;

    readln;

    lo:=(l div 3)+1;

    m:=q;

    end;

    procedure multiplied(a,b:arra;l1,l2:longint);

    var i,j:longint;

    s:string;

    begin

    l3:=l1+l2;

    next:=0;

    fillchar(c,sizeof(c),0);

    for i:=1 to l1 do

    for j:=1 to l2 do

    begin

    c:=a[i]*b[j]+c;

    if c>=1000 then

    begin

    c:=c+c div 1000;

    c:=c mod 1000;

    if i+j>l3 then inc(l3);

    end;

    end;

    while c[l3]=0 do dec(l3);

    write(c[l3]);

    for i:=l3-1 downto 1 do

    begin

    str(c[i],s);

    while length(s)

  • 0
    @ 2009-02-05 21:53:36

    高精 压位啊

信息

ID
1040
难度
7
分类
高精度 点击显示
标签
(无)
递交数
16686
已通过
3188
通过率
19%
被复制
29
上传者