题解

335 条题解

  • 0
    @ 2008-11-12 21:41:07

    这是小菜在NOIP2008之前写的最后一道高精度的题

    终于会用位压缩了

    第一次交了bak的内容,直接顶歇

    我的RP啊!

  • 0
    @ 2008-11-12 21:01:24

    不怪,虽然学pascal好长时间,不过万进制的高精度 = =

    今天还是第一次写。。

    囧去了……

  • 0
    @ 2008-11-11 23:26:05

    编译通过...

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

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

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

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

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

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

    万进制...

    program jy;

    type

    numtype=array[0..10000] of longint;

    var

    a,b,c:numtype;

    as1,as2,ans:ansistring;

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

    var

    t:numtype;

    i,x,j,p:longint;

    begin

    fillchar(t,sizeof(t),0);

    for i:=1 to b[0] do

    begin

    x:=b[i];

    for j:=1 to a[0] do

    begin

    t:=t+a[j]*x;

    p:=i+j-1;

    while t[p]>=10000 do

    begin

    t[p+1]:=t[p+1]+t[p] div 10000;

    t[p]:=t[p] mod 10000;

    p:=p+1;

    end;

    end;

    end;

    while (t[p]=0) and (p>1) do p:=p-1;

    t[0]:=p;

    mul:=t;

    end;

    function numstr(a:numtype):ansistring;

    var

    i,p:integer;

    tst:string;

    tast:ansistring;

    begin

    p:=a[0];

    str(a[p],tast);

    for i:=p-1 downto 1 do

    begin

    if a[i] div 1000=0 then tast:=tast+'0';

    if a[i] div 100=0 then tast:=tast+'0';

    if a[i] div 10=0 then tast:=tast+'0';

    str(a[i],tst);

    tast:=tast+tst;

    end;

    numstr:=tast;

    end;

    function strnum(a:ansistring):numtype;

    var

    s:string;

    begin

    fillchar(strnum,sizeof(strnum),0);

    repeat

    s:=copy(a,length(a)-3,4);

    strnum[0]:=strnum[0]+1;

    val(s,strnum[strnum[0]]);

    a:=copy(a,1,length(a)-4);

    until a='';

    end;

    begin

    readln(as1);

    readln(as2);

    a:=strnum(as1);

    b:=strnum(as2);

    c:=mul(a,b);

    ans:=numstr(c);

    writeln(ans);

    end.

  • 0
    @ 2008-11-11 19:51:15

    编译通过...

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

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

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

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

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

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

    program hly;

    const

    cmax=100000;

    base=10000;

    var

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

    c:array[1..2*cmax] of longint;

    num1,num2:ansistring;

    len1,len2:longint;

    procedure init;

    var

    i,index:longint;

    begin

    readln(num1);

    readln(num2);

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

    if length(num1) mod 40 then

    for i:=1 to 4-length(num1) mod 4 do

    num1:='0'+num1;

    if length(num2) mod 40 then

    for i:=1 to 4-length(num2) mod 4 do

    num2:='0'+num2;

    len1:=length(num1) div 4;len2:=length(num2) div 4;

    for i:=1 to len1 do

    val(copy(num1,4*i-3,4),a[len1-i+1]);

    for i:=1 to len2 do

    val(copy(num2,4*i-3,4),b[len2-i+1]);

    end;

    procedure multiply;

    var

    i,j,id,carry:longint;

    begin

    carry:=0;

    for i:=1 to len2 do

    for j:=1 to len1 do

    begin

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

    if c>=base then

    begin

    c:=c+c div base;

    c:=c mod base;

    end;

    end;

    end;

    procedure out;

    var

    st:string;

    p,i,j:longint;

    begin

    p:=len1+len2;

    while (p>0) and (c[p]=0) do

    dec(p);

    if p=0 then write('0') else

    begin

    write(c[p]);

    for i:=p-1 downto 1 do

    begin

    str(c[i],st);

    if length(st) mod 4 0 then

    begin

    for j:=1 to 4-length(st) mod 4 do

    write('0');

    write(st);

    end

    else

    write(st);

    end;

    writeln;

    end;

    end;

    begin

    init;

    multiply;

    out;

    end.

  • 0
    @ 2008-11-13 18:02:44

    编译通过...

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

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

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

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

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

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

    编译通过...

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

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

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

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

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

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

    var a,b:array[1..10000] of 0..9 ;

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

    str1,str2,te:ansistring;

    l1,l2,i,code,j:integer;

    begin

    readln(str1);

    readln(str2);

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

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

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

    if length(str1) < length(str2) then

    begin

    te:=str1;

    str1:=str2;

    str2:=te;

    end;

    l1:=length(str1);

    l2:=length(str2);

    for i:= 1 to l1 do

    val(str1[i],a[i],code);

    for i:= 1 to l2 do

    val(str2[i],b[i],code);

    for i:= l2 downto 1 do

    begin

    for j:= l1 downto 1 do

    c[10000+j-l1+i-l2]:=a[j]*b[i]+c[10000+j-l1+i-l2];

    for j:= 10000 downto 1 do

    if c[j] >=10 then begin c[j-1]:=c[j] div 10 + c[j-1] ; c[j]:=c[j] mod 10 ; end;

    end;

    for i:= 1 to 10000 do

    if c[i] 0 then break ;

    for j:= i to 10000 do

    write(c[j]);

    readln

    end.

  • 0
    @ 2008-11-10 16:42:18

    #include

    using namespace std;

    int al(int x)

    {

    int i,j,n;

    i=0;

    n=x;

    while(n!=0){n/=10;i++;}

    for(j=0;j

  • 0
    @ 2008-11-10 11:42:37

    非常好又很简洁的题~

    同时练习了高精加、高精乘单精的写法呢。

    一击必杀纪念...

    大家注意判断乘数...如果出现零 = =

    比较容易出错的地方,就是累加的移位。

    咱用的10000压缩...数据4近200ms,看楼下某牛用1000000000压秒杀,心碎...

    其实咱还加了个末尾零优化...

    读入的时候记录两个数末尾零的个数,然后删除之,再进行计算,

    最后输出这些零就可以了。

    不过貌似对这次的数据没有帮助 = =

  • 0
    @ 2008-11-10 09:07:55

    看来真是人品问题啊!

    忘记将string 改为ansistring了

    调试时为了方便看喜欢将ansistring变为

    string每次都忘记改回来,真是失败啊!

  • 0
    @ 2008-11-07 21:52:55

    万进制存储就是了,不过要用ANSISTRING(陋习……建议大家都用数组,方便快捷)

  • 0
    @ 2008-11-07 18:00:21

    4位一存的处理:

    for(i=1;i

  • 0
    @ 2008-11-06 18:59:22

    #include

    #include

    #define maxl 10000

    long a[maxl+10],b[maxl+10],c[maxl*2+10];

    void print_num(long *jj)

    {

    long i;

    for(i=jj[0];i>=1;--i)

    printf("%ld",jj[i]);

    printf("\n");

    }

    int main()

    {

    long len,i,j;

    char s[maxl+10];

    scanf("%s",s);

    a[0]=strlen(s);

    if('0'==s[0]) {printf("0\n");return 0;}

    for(i=0;i

  • 0
    @ 2008-11-05 19:24:04

    1次AC

    OH YEAH~~

  • 0
    @ 2008-11-05 09:49:19

    没想到一个难度3的题。。。。。秒杀+1次AC+我这样的菜鸟。。。。。

    编译通过...

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

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

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

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

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

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

    压缩为10000进制的就可以了,但是数组要大一点

  • 0
    @ 2008-11-03 22:55:59

    编译通过...

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

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

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

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

    什么意思啊????

  • 0
    @ 2008-10-30 22:59:52

    编译通过...

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

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

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

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

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

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

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

    压位就是 速度 (用 QWORD 九位压缩) 暴快

  • 0
    @ 2008-10-30 20:15:27

    很郁闷...看下面雅礼中学同学写的..我觉得是目前很好的一种方法...

    恩...华二的信息小组报废了....向往雅礼....

  • 0
    @ 2008-10-28 20:50:17

    编译通过...

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

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

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

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

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

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

    #include

    #define SIGN_CF_BITS 4

    #define SIGN_CF 10000

    #define PARTS 8000

    #define init() int *pa,*pb,*pc,*paend,*pbend; \

    pa=&a->s[0];pb=&b->s[0];pc=&c->s[0]; \

    paend = &a->s[a->len];pbend = &b->s;

    #define sup() pa=pc-1; \

    while (pc>paend && !*pa) {pc--;pa--;}

    typedef struct

    {

    int s[PARTS+1];

    int len;

    }hp;

    void cov(hp *x,char s[])

    {

    int i,len,t,k;

    len = strlen(s);

    k=0;

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

    {

    i=0;

    again:

    t=0;

    for (;is[k++] = t;

    }

    if (len>-SIGN_CF_BITS)

    {

    i = SIGN_CF_BITS-(len+SIGN_CF_BITS);

    goto again;

    }

    x->len = k;

    }

    void pnt(hp *x,char buf[])

    {

    int i,len,num,j=0,k,f;

    len = x->len-1;

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

    {

    num = x->s[i];

    if (nums[0];

    }

    hp x,y,z;

    char str[160000];

    int main()

    {

    while (scanf("%s",str)!=EOF)

    {

    cov(&x,str);

    scanf("%s",str);

    cov(&y,str);

    mul(&x,&y,&z);

    pnt(&z,str);

    puts(str);

    }

    return 0;

    }

  • 0
    @ 2008-10-28 20:29:09

    rp低死了...

    写个高精乘竟然还把j打成了i

    交了2次才过...

    压8位高精真不错...秒杀

  • 0
    @ 2008-10-28 08:42:34

    数组开小了~委琐的提交了6次~!!!!!

  • 0
    @ 2008-10-21 23:29:17

    10000进制需要配合long long 试用 负责越界,建议用1000进制

信息

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