51nod 1027大数乘法
题目链接: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大数乘法的更多相关文章
- 51NOD 1027 大数乘法
1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B ...
- 51 Nod 1027 大数乘法【Java大数乱搞】
1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度 ...
- 51Nod 1028 大数乘法 V2
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 分析: FFT/NTT板子题... 代码: NTT板子: #inc ...
- FFT/NTT [51Nod 1028] 大数乘法 V2
题目链接:51Nod 传送门 没压位,效率会低一点 1.FFT #include <cstdio> #include <cstring> #include <algori ...
- 51nod 1028 大数乘法 V2 【FFT模板题】
题目链接 模板题.. #include<bits/stdc++.h> using namespace std; typedef int LL; typedef double db; nam ...
- 51 Nod 1028 大数乘法 V2【Java大数乱搞】
1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A ...
- ACM学习历程—51NOD1028 大数乘法V2(FFT)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...
- [POJ] #1001# Exponentiation : 大数乘法
一. 题目 Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 156373 Accepted: ...
- 用分治法实现大数乘法,加法,减法(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 ...
随机推荐
- 个人对AutoResetEvent和ManualResetEvent的理解(转载)
仅个人见解,不对之处请指正,谢谢. 一.作用 AutoResetEvent和ManualResetEvent可用于控制线程暂停或继续,拥有重要的三个方法:WaitOne.Set和Reset. 这三个方 ...
- AngularJS安装配置与基础概要整理(上)
以前整理的,可供参考. 安装: 1.首先要安装node.js和它的npm包管理系统.(nodejs相关待整理) 2.安装grunt .grunt是一个基于任务的Javascript工程命令行构建工具. ...
- ActiveMQ的使用笔记(基本实现原理)
具体原理不进行深入,会用就好. 第一:当然是先安装ActiveMQ,选择操作系统位数,安装成功以后,输入网址http://ip:8161/admin/,会出现相关页面,账号密码都是admin.在这个页 ...
- C#使用二叉树算法设计一个无限分级的树表
效果图: 数据库: 操作树的示意图: 控制器代码: using Dw.Business; using Dw.Entity; using Dw.Utilities; using System; usin ...
- 在Repeater中嵌套使用Repeater
在一般的网站中浏览类别的用户控件通常都位于大多数 ASP.NET 页的左边,它使用户能够按类别快速的查找产品.最近遇到一个客户,因为在他网站上展示的产品并不多,所以要求在原有类别浏览的基础上将产品也加 ...
- MVC4 Filter 验证客户端访问类型(移动端、PC端)
Filter: 1 /// <summary> /// 检测是否是手机访问 /// </summary> public class IsMobileFilter : Actio ...
- python开发进阶之路(一)
哎!好久没有写博客了,怪想念的,今天听了偶像的讲解,好多以前感觉很模糊的概念今天一下子就明朗了.下面就来整理一下今天的收获 一.如何成为一名优秀的开发人员 1.1 得先对自己使用的开发语言了如指掌, ...
- python发送邮件方法
1.普通文本邮件 #!/usr/bin/env python # -*- coding:utf-8 -*- import smtplib from email.mime.text import MIM ...
- Create Your Tab and LayerTabMenu In Katana
感谢 http://tool.lu/pyc/ 这个牛逼的网站能反编译pyc...他妈的Katana太他妈无耻了,竟然不让自定义加Node Tab Content....只能反编译他的东西了... 研究 ...
- 禁止输入中文 与 禁止输入数字在phonegap api环境效果
例子如下: <!doctype html> <html> <head> <meta charset="utf-8"> <tit ...