题目链接:51nod 1027大数乘法

直接模板了。

 #include<cstdio>
#include<cstring>
using namespace std;
const int N = ;
const int DLEN = ;
const int mod = ;
int alen, blen;
int ans_len;
char a1[N], b1[N];
int a[], b[];
int ans[]; void BigInt(const char s[], int (&c)[], int &len){
memset(c, , sizeof(c));
int L = strlen(s);
len = L / DLEN;
if(L%DLEN) len++;
int cnt = ;
for(int i = L-; i >= ; i -= DLEN){
int k = i - DLEN + ;
if(k < ) k = ;
int t = ;
for(int j = k; j <= i; ++j)
t = t * + s[j] - '';
c[cnt++] = t;
}
}
void multi(){
int i, j;
for(i = ; i < alen; ++i){
int up = ;
for(j = ; j < blen; ++j){
int t = a[i] * b[j] + ans[i+j] + up;
up = t / mod;
ans[i+j] = t % mod;
}
if(up != )
ans[i+j] = up;
}
ans_len = alen + blen;
while(ans[ans_len-] == && ans_len > )
ans_len--; printf("%d", ans[ans_len-]);
for(i = ans_len-; i >= ; i--)
printf("%04d", ans[i]);
puts("");
}
int main(){
scanf("%s%s", a1, b1);
BigInt(a1, a, alen);
BigInt(b1, b, blen);
multi();
return ;
}

51nod 1027大数乘法的更多相关文章

  1. 51NOD 1027 大数乘法

    1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题   给出2个大整数A,B,计算A*B的结果.   Input 第1行:大数A 第2行:大数B (A,B ...

  2. 51 Nod 1027 大数乘法【Java大数乱搞】

    1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度  ...

  3. 51Nod 1028 大数乘法 V2

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 分析: FFT/NTT板子题... 代码: NTT板子: #inc ...

  4. FFT/NTT [51Nod 1028] 大数乘法 V2

    题目链接:51Nod 传送门 没压位,效率会低一点 1.FFT #include <cstdio> #include <cstring> #include <algori ...

  5. 51nod 1028 大数乘法 V2 【FFT模板题】

    题目链接 模板题.. #include<bits/stdc++.h> using namespace std; typedef int LL; typedef double db; nam ...

  6. 51 Nod 1028 大数乘法 V2【Java大数乱搞】

    1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A ...

  7. ACM学习历程—51NOD1028 大数乘法V2(FFT)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...

  8. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  9. 用分治法实现大数乘法,加法,减法(java实现)

    大数乘法即多项式乘法问题,求A(x)与B(x)的乘积C(x),朴素解法的复杂度O(n^2),基本思想是把多项式A(x)与B(x)写成 A(x)=a*x^m+b B(x)=c*x^m+d 其中a,b,c ...

随机推荐

  1. ios - block数据的回调

    block在代理,kvo中传递数据效率最高 实现原理 控制器B想传递数据给控制器A.通过在B控制器中创建Block类型的类,创建方法,方法参数是刚才创建的block类型的变量.在方法实现的内部调用参数 ...

  2. python - 文件迭代

    >>> f=open('passwd','r')>>> for lines in f:... print lines >>> f=open('pa ...

  3. c# signalr聊天室开源资料

    SignalR+LayIM源码: http://www.cnblogs.com/panzi/p/5742089.html 钉钉客户端源码: http://www.cnblogs.com/loveson ...

  4. 利用jquery获取html中被选中的input的值

    单个按钮 <div id="wrap"> <input type="radio" name="payMethod" val ...

  5. mongo基本语句

    批量更新 db.test.updateMany({name:'test'},{$set:{value:1}}) 单更新 db.test.update({name:'test'},{$set:{valu ...

  6. mfc ui3

    引用:http://www.cnblogs.com/rainbowzc/archive/2010/06/02/1749872.html 本文专题讨论VC中的界面美化,适用于具有中等VC水平的读者.读者 ...

  7. JSP-11-Servlet

    1 初识Servlet Ø  Servlet做了什么 本身不做业务 只接收请求并决定调用哪个JavaBean去处理请求 确定用哪个页面来显示处理返回的数据 Ø  Servlet 是什么 Servlet ...

  8. web前端本地测试方法

    在大型项目中的前端测试与开发,通常使用git clone将整个工程目录下载下来,然后本地运行调试. 然而,当一个项目已经发布到测试机上,需要临时查看某个页面的效果或修改某个页面时,clone整个工程目 ...

  9. sof文件和NIOS II的软件(elf)合并为jic文件以使用Quartus Programmer烧写

    将Altera FPGA的sof文件和NIOS II的elf固件合并为一个jic文件以使用Quartus Programmer烧写   我们在学习和调试NIOS II工程的时候,一般都是先使用Quar ...

  10. python入门练习题1

    常见python入门练习题 1.执行python脚本的两种方法 第一种:给python脚本一个可执行的权限,进入到当前存放python程序的目录,给一个x可执行权限,如:有一个homework.py文 ...