题解

336 条题解

  • 0
    @ 2010-07-23 21:29:35

    一次ac

    新手过的第一道难度三的题!good!

    规规矩矩的做法,没有压位,没有那么复杂,10进制普通做法就行

    string要换

    program p1040;

    var

    l1,l2,l3,i,j,k,l:longint;

    a,b:array[0..999999]of longint;

    s1,s2:ansistring;

    begin

    readln(s1);readln(s2);

    l1:=length(s1);l2:=length(s2);

    for i:=0 to l1-1 do

    a[i]:=ord(s1[l1-i])-ord('0');

    for i:=0 to l2-1 do b[i]:=ord(s2[l2-i])-ord('0');

    for i:=l1-1 downto 0 do

    begin

    for j:=l2-1 downto 1 do

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

    a[i]:=a[i]*b[0];

    end;

    k:=l1+l2-1;

    for i:=0 to k-1 do

    begin

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

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

    end;

    if a[k]>0 then k:=k+1;

    for i:=k-1 downto 0 do write(a[i]);

    end.

    编译通过...

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

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

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

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

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

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

  • 0
    @ 2010-04-09 15:56:16

    var

    s1,s2:ANSIstring;

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

    c:array[1..1000000]of longint;

    i,j:longint;

    begin

    readln(s1);

    readln(s2);

    fillchar(a,sizeof(a),0);

    fillchar(b,sizeof(b),0);

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

    for i:=1 to length(s1)do

    a[length(s1)-i+1]:=ord(s1[i])-48;

    for i:=1 to length(s2)do

    b[length(s2)-i+1]:=ord(s2[i])-48;

    for i:=1 to length(s1)do begin

    for j:=1 to length(s2)do begin

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

    end;

    end;

    j:=0;

    repeat

    inc(j);

    if c[j]>=10

    then begin

    c[j+1]:=c[j+1]+c[j] div 10;

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

    end;

    until c[j+1]=0;

    for i:=j downto 1 do

    write(c[i]);

    writeln;

    end.

    编译通过...

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

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

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

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

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

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

    随能帮我看看为什么超时

    或怎样才不超时!

  • 0
    @ 2009-11-20 13:22:04

    program p1040_1;

    type arr=record

    s:array[0..5000]of int64;

    len:longint;

    end;

    var

    x,i,j,l:longint;

    str:ansistring;

    a,b:arr;

    function mul(a,b:arr):arr;

    var

    c:arr;

    i,j:longint;

    begin

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

    for i:=1 to a.len do

    for j:=1 to b.len do

    begin

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

    inc(c.s,c.s div 100000000);

    c.s:=c.s mod 100000000;

    end;

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

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

    mul:=c;

    end;

    begin

    readln(str);

    l:=length(str);

    a.len:=l div 8;

    for i:=1 to a.len do

    val(copy(str,l-i*8+1,8),a.s[i]);

    if l mod 80 then begin inc(a.len);val(copy(str,1,l mod 8),a.s[a.len]); end;

    readln(str);

    l:=length(str);

    b.len:=l div 8;

    for i:=1 to b.len do

    val(copy(str,l-i*8+1,8),b.s[i]);

    if l mod 80 then begin inc(b.len);val(copy(str,1,l mod 8),b.s); end;

    a:=mul(a,b);

    write(a.s[a.len]);

    for i:=a.len-1 downto 1 do

    begin

    x:=10000000;

    if a.s[i]=0 then

    for j:=1 to 8 do

    write(0);

    while a.s[i]0 do

    begin

    if a.s[i] div x=0 then begin write(0);x:=x div 10; end

    else begin write(a.s[i]);a.s[i]:=0 end;

    end;

    end;

    end.

    压了8位了 为什么还是没有秒杀 哎

    • @ 2013-08-01 20:36:36

      用了过程会浪费一点点时间

  • 0
    @ 2009-11-10 11:39:52

    压位

    program p1040;

    var a,b,c:array[0..20010] of longint;

    k1,k2,k,i,j,n1,n2,jsq:longint;

    x:char;

    st:ansistring;

    begin

    readln(st);

    n1:=length(st);

    k1:=7-(n1 mod 4);

    jsq:=0;

    while jsq='0') and (x0) do k:=k-1;

    if k=0 then writeln(0) else

    begin

    write(c[k]);

    for i:=k-1 downto 1 do

    begin

    if c[i]>999 then write(c[i])

    else if c[i]>99 then write('0',c[i])

    else if c[i]>9 then write('00',c[i])

    else write('000',c[i]);

    end;

    writeln;

    end;

    end.

  • 0
    @ 2009-11-08 21:27:26

    #include"stdio.h"

    #include"string.h"

    int main()

    {

    char m[15000],n[15000];

    static long int im[3000],in[3000];

    long int sum[100000]={0};

    int mlen,nlen;

    int i,ii=0,j,jj=0,mk=0,nk=0,sk=0;

    int x;

    int t=0;

    int flag=0;

    scanf("%s",m);

    getchar();

    scanf("%s",n);

    mlen=strlen(m);

    nlen=strlen(n);

    for(i=0;i

  • 0
    @ 2009-11-07 10:01:31

    Flag   Accepted

    题号   P1040

    类型(?)   数论 / 数值

    通过   3145人

    提交   19554次

    通过率   16%

    难度   3

  • 0
    @ 2009-11-06 17:18:40

    #include

    #include

    using namespace std;

    int a[40001],b[40001],s[40001];

    int la,lb,ls,i,ja,ka,jb,kb,j,k;

    string sa,sb;

    int main(){

    cin>>sa;

    ka=sa.length();

    for(i=1;i>2;

    a[ja]=a[ja]*10+sa-48;

    }

    la=(ka+3)>>2;

    cin>>sb;

    kb=sb.length();

    for(i=1;i>2;

    b[jb]=b[jb]*10+sb-48;

    }

    lb=(kb+3)>>2;

    ls=0;

    for(i=1;i

  • 0
    @ 2009-11-06 09:04:14

    编译通过...

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

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

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

    ├ 测试数据 04:运行时错误...|错误号: 200

    200被零除?

  • 0
    @ 2009-11-04 18:09:41

    var

    a,b:array[0..40001] of longint;

    l1,l2,len,i,k:longint;

    str:ansistring;

    procedure multiply;

    var i,j:integer;

    begin

    for i:=l1-1 downto 0 do

    begin

    for j:=l2-1 downto 1 do

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

    a[i]:=a[i]*b[0];

    end;

    for i:=0 to k-1 do

    begin

    inc(a,a[i] div 10);

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

    end;

    if a[k]0 then inc(k,1);

    end;

    begin

    readln(str);

    len:=length(str);

    l1:=len;

    for i:=0 to len-1 do

    a[len-i-1]:=ord(str)-ord('0');

    readln(str);

    len:=length(str);

    l2:=len;

    for i:=0 to len-1 do

    b[len-i-1]:=ord(str)-ord('0');

    k:=l1+l2-1;

    multiply;

    for i:=k-1 downto 0 do

    write(a[i]);

    end.

    谁说用万进制了?

    我虽然耗时384MS 但用的是十进制的!

    数据开大点 不是过不了!

  • 0
    @ 2009-11-02 21:52:25

    离心水泵

  • 0
    @ 2009-11-02 21:50:38

    var

    m,n:ansistring;

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

    len1,len2,len3,i,j,t:longint;

    begin

    kk[1]:=1;

    read(m);readln;readln(n);

    len1:=length(m);

    len2:=length(n);

    for i:=1 to len1 do a[i]:=ord(m[len1-i+1])-48;

    for i:=1 to len2 do b[i]:=ord(n[len2-i+1])-48;

    begin

    for i:=1 to len1 do

    for j:=1 to len2 do

    begin

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

    end;

    end;

    len1:=len2+len1;

    for i:=1 to len1 do if c[i]>=10 then

    begin

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

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

    end;

    for i:=1 to len1 do if c[i]0 then t:=i;

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

    end.

    太烦了。。。。又过老。。太简单老。。。。离我得ioi满分的日子已经几年老。。。。好想念那些在希腊参赛的日子。。。。好想那个老师。。。。

    • @ 2014-03-18 19:38:06

      fuck your mother 编译错误

  • 0
    @ 2009-11-02 10:41:27

    万进制

    数组开不够 说我超时。。。

    编译通过...

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

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

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

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

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

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

    program ex;

    type arr=array[0..5000]of int64;

    var i,j:longint;

    s1,s2:ansistring;

    a,b,c:arr;

    procedure init;

    var i,j:longint;

    begin

    readln(s1);

    while (s1[1]='0')and(length(s1)>1) do delete(s1,1,1);

    readln(s2);

    while (s2[1]='0')and(length(s2)>1) do delete(s2,1,1);

    a[0]:=length(s1) div 4 +ord(length(s1) mod 40);

    for i:=1 to a[0]-1 do

    begin

    val(copy(s1,length(s1)-3,4),a[i]);

    delete(s1,length(s1)-3,4);

    end;

    val(s1,a[a[0]]);

    b[0]:=length(s2) div 4 +ord(length(s2) mod 40);

    for i:=1 to b[0]-1 do

    begin

    val(copy(s2,length(s2)-3,4),b[i]);

    delete(s2,length(s2)-3,4);

    end;

    val(s2,b[b[0]]);

    end;

    procedure mul;

    var i,j:longint;

    begin

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

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

    for i:=1 to a[0] do

    for j:=1 to b[0] do

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

    for i:=1 to c[0] do

    begin

    inc(c,c[i] div 10000);

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

    end;

    while c[c[0]+1]>0 do

    begin

    inc(c[0]);

    inc(c[c[0]+1],c[c[0]] div 10000);

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

    end;

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

    end;

    procedure print;

    var i,j:longint;

    ans:ansistring;

    begin

    write(c[c[0]]);

    for i:=c[0]-1 downto 1 do

    begin

    if c[i]

  • 0
    @ 2009-10-31 09:15:58

    4位压缩法:

    编译通过...

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

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

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

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

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

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

  • 0
    @ 2009-10-29 22:51:55

    var n,m,x,y:ansistring;

    q,w,e,i,j,l,k,z1,z2:longint;

    a,b,c:array[1..100000]of int64;

    procedure cheng;

    var j,i,r,u:longint;

    begin

    u:=0;

    for i:=1 to q do

    for j:=1 to w do begin

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

    c:=c+cdiv 10000;

    c:=cmod 10000;

    if c[q+w]0 then u:=1;

    end;

    for i:=q+w-1+u downto 1 do

    begin

    if iq+w-1+u then

    if c[i]

  • 0
    @ 2009-10-28 13:40:52

    关于这个万位的高精度乘法,一定要进行优化!

    string一定不行,它最大能开到255,所以要用字符串只能用ansistring;

    当然不用也行,用文件函数进行输入。我比较懒,用了ansistring;

    截一位,最后一组数据会过不了!

    ∵ longint的范围是-(2^31)~~~~(2^31)-1

    9999*9999

  • 0
    @ 2009-10-13 13:05:48

    program gjdcf;

    var a,b,c,d:array[1..50] of longint;

    i,j,k,p:longint;

    begin

    fillchar(a,sizeof(a),100);

    fillchar(b,sizeof(b),100);

    randomize;

    for i:=20 downto 1 do

    begin

    a[i]:=random(9)+1;

    write(a[i]);

    end;

    write('*');

    writeln;

    for i:=20 downto 1 do

    begin

    b[i]:=random(9)+1;

    write(b[i]);

    end;

    write('=');

    writeln;

    for j:=20 downto 1 do

    c[j]:=a[j];

    for i:=1 to 20 do

    begin

    a:=a+(a[i]*b[i])div 10;

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

    while a[i] >=10 do

    begin

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

    k:=a[i];

    inc(i);

    a[i]:=a[i]+(k div 10);

    end;

    while

  • 0
    @ 2009-10-11 20:01:09

    编译通过...

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

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

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

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

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

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

    我果然善于把程序写得很长很长……

    const filename='p1040';

    var

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

    c:array[1..5000]of longint;

    s:ansistring;

    i,j,l,l2,x,k:longint;

    begin

    assign(input,filename+'.in');reset(input);

    assign(output,filename+'.out');rewrite(output);

    readln(s);

    l:=length(s)div 4;

    if length(s)mod 40then

    begin

    inc(l);

    for i:=l downto 2 do

    begin

    val(copy(s,length(s)-3,4),a[l-i+1]);

    delete(s,length(s)-3,4);

    end;

    val(s,a[l]);

    end

    else

    for i:=l downto 1 do

    begin

    val(copy(s,length(s)-3,4),a[l-i+1]);

    delete(s,length(s)-3,4);

    end;

    // for i:=1 to l do writeln(a[i]); writeln;

    ///////////////

    readln(s);

    l2:=length(s)div 4;

    if length(s)mod 40then

    begin

    inc(l2);

    for i:=l2 downto 2 do

    begin

    val(copy(s,length(s)-3,4),b[l2-i+1]);

    delete(s,length(s)-3,4);

    end;

    val(s,b[l2]);

    end

    else

    for i:=l2 downto 1 do

    begin

    val(copy(s,length(s)-3,4),b[l2-i+1]);

    delete(s,length(s)-3,4);

    end;

    //for i:=1 to l2 do writeln(b[i]);

    for i:=1 to l do

    for j:=1 to l2 do

    begin

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

    if c>10000 then

    begin

    c:=c[j+i-1]div 10000+c;

    c:=cmod 10000;

    end

    end;

    l:=l+l2;

    while c[l]=0do dec(l);write(c[l]);

    for i:=l-1 downto 1 do

    begin

    k:=c[i];

    for j:=3 downto 1 do

    begin

    if k div 10=0then write(0);

    k:=k div 10;

    end;

    write(c[i]);

    end;

    writeln;

    close(input);close(output);

    end.

    友情提供二数据(自己编的):

    in

    1564665465

    775795268

    out

    1213860063750019620

    in

    443

    1432531

    out

    634611233

    这个程序在桌面上留个.exe以后用来代替calc.exe计算高精乘法……

  • 0
    @ 2009-10-10 19:21:19

    压四位,秒杀

  • 0
    @ 2009-10-06 09:36:10

    编译通过...

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

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

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

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

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

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

    难得一次AC撒花庆祝一下,,不过MS我的程序时最长的囧

    10^8进制

    program s1040;

    var

    a,b,c,d,ans,final:array [1..30000] of qword;

    s:ansistring;

    i,j,nb,nc,m,n:longint;

    procedure doe;

    var i,j:longint;

    begin

    for i:=1 to nb do

    begin

    fillchar(d,sizeof(d),0);

    for j:=1 to nc do

    d[j+i-1]:=c[j]*b[i];

    for j:=1 to nc+i-1 do

    begin

    ans[j]:=d[j]+ans[j];

    if ans[j]>=100000000 then

    begin

    ans[j+1]:=ans[j+1]+ans[j] div 100000000;

    ans[j]:=ans[j] mod 100000000;

    end;

    end;

    end;

    end;

    {main}//其实就是读入输出= =

    begin

    readln(s);

    fillchar(a,sizeof(a),0);

    for i:=1 to length(s) do

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

    if length(s) mod 8 =0 then nb:=length(s) div 8 else

    nb:=length(s) div 8+1;

    for i:=1 to nb do

    begin

    m:=0;

    for j:=8 downto 1 do

    m:=m*10+a[(i-1)*8+j];

    b[i]:=m;

    end;

    readln(s);

    fillchar(a,sizeof(a),0);

    for i:=1 to length(s) do

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

    if length(s) mod 8 =0 then nc:=length(s) div 8 else

    nc:=length(s) div 8+1;

    for i:=1 to nc do

    begin

    m:=0;

    for j:=8 downto 1 do

    m:=m*10+a[(i-1)*8+j];

    c[i]:=m;

    end;

    fillchar(a,sizeof(a),0);

    //读数直接复制了一下= =写个过程MS也不错

    doe; //操作

    n:=nb+nc+1;

    while (ans[n]=0) and (n>=2) do dec(n);

    for i:=1 to n do

    for j:=1 to 8 do

    begin

    final[(i-1)*8+j]:=ans[i] mod 10;

    ans[i]:=ans[i] div 10;

    end;

    n:=n*8;

    while (final[n]=0) and (n>=2) do dec(n);

    for i:=n downto 1 do

    write(final[i]);

    end.

  • 0
    @ 2009-10-01 17:15:54

    ├ 测试数据 04:运行时错误...|错误号: -1073741571

    这是什么东西,有谁可以告诉我

信息

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