题目链接: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. file_get_contents抓取远程URL内容

    /** * POST URL * @param $url * @param null $post * @return false / string */ public static function ...

  2. 移动端开发tips

    为什么使用touch click有300sm的延迟 touch支持多点触摸 手势操作

  3. oauth协议

    微博 : 新浪 腾讯 OAuth 新浪微博   APP开发 步骤:1.注册新浪开发者账号 获取以下信息 client_id  123456  标示应用身份的  唯一的  有的也叫App Key sec ...

  4. 学生各门课程成绩统计SQL语句大全

    学生成绩表(stuscore): 姓名:name 课程:subject 分数:score 学号:stuid 张三 数学 89 1 张三 语文 80 1 张三 英语 70 1 李四 数学 90 2 李四 ...

  5. 最长公共上升子序列(LCIS)

    最长公共上升子序列慕名而知是两个字符串a,b的最长公共递增序列,不一定非得是连续的.刚开始看到的时候想的是先用求最长公共子序列,然后再从其中找到最长递增子序列,可是仔细想一想觉得这样有点不妥,然后从网 ...

  6. html5,导航

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  7. phpcms V9 MVC模式 与 URL访问解析

    [1]URL访问解析 观察访问网页时的网址,可以得出模块访问方法,如下示例: http://www.abcd.com.cn/phpcms/index.php?m=content&c=index ...

  8. 用mysql++读写二进制

    方法1: // mysqlTest.cpp : 定义控制台应用程序的入口点. #include "stdafx.h" #include <mysql++.h> #inc ...

  9. 随机获取数据库中的某一条数据(基于yii2框架开发)

    注意: 使用PHP函数array_rand()得到的是这个数组中的那个值相对应的下标键值,需要配合原来的数组进行,例如: $rand_keys = array_rand($ids,1); $id = ...

  10. 完整成功配置wamp server小记

    首先安装最新版本的wamp server,这是必须的! 配置默认”www目录”的路径(可选):下面以改为D:\site为例.打开wamp\scripts\config.inc.php第47行,$www ...