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 ...
随机推荐
- Docker的私有仓库
server 192.168.1.107 registry ---push client 192.168.1.103 --pull [192.168.1.107 ...
- Eclipse设置自动换行
Eclipse 使用系统内置的“ Text Editor ”做为文本编辑器,这个文本编辑器有一个问题,就是文本无法换行.这个问题在显示上给人们带来不少麻烦. 终于有人忍不住开发了一个扩展插件 Word ...
- request.GetResponse 400错误处理方法
问题描述:在使用request.GetResponse时,如果是400错误,将抛出异常信息,而获取不到返回内容,所以返回的内容只能在catch上面获取,转载于 http://blog.csdn.net ...
- 最近面试的题目(WEB、Service、SQL、JavaScript)
整理一下最近面试被问到的主要题目.由于本人主要是做WEB及WEB SERVICE这块,使用的语言主要是C#,数据库主要用到的也是MSSQL.所以就分成这些块来整理(有些是在面试之后才意识到回答不对), ...
- Rstudio使用记录
2016/11/1 目前新建两个project:project1(有两个变量x,y)&&project2(无变量)
- vue.js慢速入门(2)
4.组件使用基础 什么是组件?组件可以理解为可重用的自定义HTML. 可以使用一堆组件来构造大型应用,任意类型的应用界面都可以抽象为一个组件树: 可以把组件代码按照template.style.scr ...
- Jmeter中察看结果树中的响应数据,中文显示乱码问题处理
打开apache-jmeter-xxx\bin\jmeter.properties文件,搜索"encoding"关键字,找到如下配置: # The encoding to be u ...
- HTML5 Web Storage
Web Storage是HTML5 API提供一个新的重要的特性: 最新的Web Storage草案中提到,在web客户端可用html5 API,以Key-Value形式来进行数据持久存储: 目前主要 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(31)-MVC使用RDL报表
系列目录 这次我们来演示MVC3怎么显示RDL报表,坑爹的微软把MVC升级到5都木有良好的支持报表,让MVC在某些领域趋于短板 我们只能通过一些方式来使用rdl报表. Razor视图不支持asp.ne ...
- udhcpc命令【转】
udhcpc -i usb0 route 转自:http://blog.csdn.net/hshl1214/article/details/8684740 由于要使用网络通讯,所以不可避免的要用到dh ...