[vijos P1040] 高精度乘法

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

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

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

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

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

时间: 2024-08-03 19:23:54

[vijos P1040] 高精度乘法的相关文章

高精度乘法程序

对于超过20位的数的乘法问题,我们无法使用普通的方法!!!即使是longlong也会超出范围的!像这样的数,我们只能使用高精度的知识利用数组的方法解决问题!对于高精度乘法的问题,其实思路和高精度加法的思路差不多,都需要使用字符数组来存放每次算完的结果!        1  2  3        *4  5  6    ________________      12  15  18   8  10  124  5   6  _____________________4 13   28   27

POJ 1306 Combinations 高精度乘法

题目大意:给出mn,让你求C(m,n). 思路:公式都给你了,就100,暴力就可以关键还是高精度.如果按照算法"它让你怎么做你就怎么做",那么很显然你需要写一个高精度除法.然而可以证明,这个除法是不会产生余数的.所以我们可以数论分析,然后避免高精度除法. 方法就是暴力求每个数的质因数,然后把被除数和除数相同的质因数消去,最后除数肯定会被消没.这样只要做高精度乘法就可以了. CODE: #include <cstdio> #include <cstring> #i

poj1001(高精度乘法)

1.题目表述 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 135893   Accepted: 33256 Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation o

真真真&#183;?高精度乘法!!!!!

RX-0奉上哈哈哈哈哈哈哈哈哈哈哈哈哈™™™ 先奉上真真真·高精度乘法源代码: 高精度乘法 RX-0制作最后修改:2016年7月6日#include<stdio.h>#include<string.h>#include<math.h>char s[10000],b;int a[10000];int c[10000];int main(){ int x,l=0,y=1,i,j,m,l1=0; long long s1=0; //freopen("hp.in&qu

[转]高精度乘法计算

转载自: Daywei 高精度乘法计算 高精度乘法计算基础 1.高精度浮点运算方法 高精度浮点(Floating Point,FP)运算可以转换成整数型运算.由于高精度浮点数可以看成是由整数部分(Integer Part,IP)与小数部分(Decimal Part,DP)的组合,因此其乘法可以看成以下3种运算的组合,即整数x整数(IxI).整数x小数(IxD)和小数x小数(DxD).用表达式表示, 则FP1*FP2=IP1*IP2+(IP1*DP2+IP2*DP1)+DP1*DP2 (1)对于I

【PKU1001】Exponentiation(高精度乘法)

Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 145642   Accepted: 35529 Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the n

HDU 1042.N!【高精度乘法】【8月24】

N! Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, process to the end of file. Output For each N, output N! in one line. Sample Input 1 2 3 Sample Output 1 2 6 高精度乘法.数组存,每一位存5位数,不然会严重超时.另外,

高进度加法与高精度乘法

正整数的高精度加法和高精度乘法(C++) 加法运算如下: // 高精度加法 string add(string a, string b) { // 确保 a >= b if (a.size() < b.size()) { string temp = a; a = b; b = temp; } int len1 = a.size(), len2 = b.size(); // a, b前缀补零 ,比如 a = 12345, b = 678时,补零之后 a = 012345,b = 0000678.

洛谷 P1303 A*B Problem 高精度乘法

P1303 A*B Problem 时空限制1s / 128MB 题目描述 求两数的积. 输入输出格式 输入格式: 两行,两个数. 输出格式: 积 输入输出样例 输入样例#1: 1 2 输出样例#1: 2 说明 每个数字不超过10^2000,需用高精 ------------------------------------------------------------------------------------------------ 既然有了高精度加减法,那就有高精度乘法 跟我们平时计算