码迷,mamicode.com
首页 > 其他好文 > 详细

[vijos P1040] 高精度乘法

时间:2014-11-05 01:45:42      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   ar   os   for   sp   数据   

如果这次noip没考好,完全是因为从7月29日之后就没有再写过程序了。说起来,真是一个泪流满面的事实…

那这样一个弱智题练手恢复代码能力,竟然还花了我两个晚上(当然不是两整个晚上…)

第一天TLE了,好在我机智,一看到解题里说要压位就自动脑补出压位了。

代码风格非常诡异,弱智题竟然写到2KB我也是醉了。

bubuko.com,布布扣
program vijos_p1040;
const maxn=10020;
var a,b,aa,bb:array[1..maxn] of integer;
    c:array[1..2*maxn] of integer;
    ma,mb,i,j,t,ca,cb:integer;
    ch:char;
begin
  //assign(input,himul.in4);reset(input);
  //assign(output,himul.ou4);rewrite(output);
  i:=0;
  //input num a
  while not eoln do
    begin
      read(ch);
      inc(i);
      a[i]:=ord(ch)-ord(0);
    end;
  ma:=i;
  readln;
  //reverse num a
  for i:=1 to ma div 2 do
    begin
      t:=a[i];a[i]:=a[ma-i+1];a[ma-i+1]:=t;
    end;
  //compress num a
  for i:=1 to (ma div 2)+1 do
    aa[i]:=a[2*i-1]+a[2*i]*10;
  //input num b
  i:=0;
  while not eoln do
    begin
      read(ch);
      inc(i);
      b[i]:=ord(ch)-ord(0);
    end;
  mb:=i;
  //reverse num b
  for i:=1 to mb div 2 do
    begin
      t:=b[i];b[i]:=b[mb-i+1];b[mb-i+1]:=t;
    end;
  for i:=1 to (mb div 2)+1 do
    bb[i]:=b[2*i-1]+b[2*i]*10;
  //multi
  ca:=ma div 2+1;
  cb:=mb div 2+1;
  for i:=1 to cb do
    begin
      for j:=1 to ca do
        begin
          c[i+j-1]:=c[i+j-1]+aa[j]*bb[i];
          if c[i+j-1]>=100 then
            begin
              c[i+j]:=c[i+j]+c[i+j-1] div 100;
              c[i+j-1]:=c[i+j-1] mod 100;
            end;
        end;
    end;
  j:=ca+cb+10;
  while c[j]=0 do dec(j);
  write(c[j]);
  for i:=j-1 downto 1 do
   begin
     if c[i]>=10 then write(c[i]) else write(0,c[i]);
   end;
  writeln;
  //close(input);close(output);
end.
高精度乘法

 

测试数据 #0: Accepted, time = 0 ms, mem = 732 KiB, score = 25

测试数据 #1: Accepted, time = 15 ms, mem = 732 KiB, score = 25

测试数据 #2: Accepted, time = 15 ms, mem = 736 KiB, score = 25

测试数据 #3: Accepted, time = 608 ms, mem = 732 KiB, score = 25

[vijos P1040] 高精度乘法

标签:style   blog   http   color   ar   os   for   sp   数据   

原文地址:http://www.cnblogs.com/Sky-Grey/p/4075238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!