题目大意:rt

题解:将长度为 N 的大整数看作是一个 N-1 次的多项式,利用 FFT 计算多项式的卷积即可。

代码如下

#include <bits/stdc++.h>
using namespace std;
typedef complex<double> cp;
const int maxn=2e5+10;
const double pi=acos(-1); int n,tot=1,bit,rev[maxn],ans[maxn];
cp a[maxn],b[maxn];
char s[maxn]; void read_and_parse(){
scanf("%d%s",&n,s),--n;
for(int i=0;i<=n;i++)a[i]=s[n-i]-'0';
scanf("%s",s);
for(int i=0;i<=n;i++)b[i]=s[n-i]-'0';
} void fft(cp *t,int type){
for(int i=0;i<tot;i++)if(i<rev[i])swap(t[i],t[rev[i]]);
for(int mid=1;mid<tot;mid<<=1){
cp wn(cos(pi/mid),type*sin(pi/mid));
int len=mid<<1;
for(int j=0;j<tot;j+=len){
cp w(1,0);
for(int k=0;k<mid;k++,w*=wn){
cp x=t[j+k],y=w*t[j+mid+k];
t[j+k]=x+y,t[j+mid+k]=x-y;
}
}
}
} void solve(){
int m=2*n;
while(tot<=m)tot<<=1,++bit;
for(int i=0;i<tot;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
fft(a,1),fft(b,1);
for(int i=0;i<tot;i++)a[i]=a[i]*b[i];
fft(a,-1);
for(int i=0;i<tot;i++)ans[i]=(int)(a[i].real()/tot+0.5);
for(int i=0;i<tot;i++)ans[i+1]+=ans[i]/10,ans[i]%=10;
while(tot>0&&!ans[tot])--tot;
for(int i=tot;~i;i--)printf("%d",ans[i]);
} int main(){
read_and_parse();
solve();
return 0;
}

【洛谷P1919】A*B Problem升级版的更多相关文章

  1. 洛谷 P1919 A*B Problem升级版

    妈妈我终于会\(A*B\ problem\)啦~~ 题目大意: 给你两个正整数 \(a,b\),求\(a*b\) 其中\(a,b\le 10^{1000000}\) 我们只要把多项式\(A(x)=\s ...

  2. 洛谷P1919 A*B problem 快速傅里叶变换模板 [FFT]

    题目传送门 A*B problem 题目描述 给出两个n位10进制整数x和y,你需要计算x*y. 输入输出格式 输入格式: 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数 ...

  3. 洛谷P1919 【模板】A*B Problem升级版 题解(FFT的第一次实战)

    洛谷P1919 [模板]A*B Problem升级版(FFT快速傅里叶) 刚学了FFT,我们来刷一道模板题. 题目描述 给定两个长度为 n 的两个十进制数,求它们的乘积. n<=100000 如 ...

  4. 洛谷1001 A+B Problem

    洛谷1001 A+B Problem 本题地址:http://www.luogu.org/problem/show?pid=1001 题目描述 输入两个整数a,b,输出它们的和(|a|,|b|< ...

  5. 洛谷P1553 数字翻转(升级版)

    题目链接 https://www.luogu.org/problemnew/show/P1553 题目描述 给定一个数,请将该数各个位上数字反转得到一个新数. 这次与NOIp2011普及组第一题不同的 ...

  6. 洛谷1303 A*B Problem 解题报告

    洛谷1303 A*B Problem 本题地址:http://www.luogu.org/problem/show?pid=1303 题目描述 求两数的积. 输入输出格式 输入格式: 两个数 输出格式 ...

  7. 洛谷1601 A+B Problem(高精) 解题报告

    洛谷1601 A+B Problem(高精) 本题地址:http://www.luogu.org/problem/show?pid=1601 题目背景 无 题目描述 高精度加法,x相当于a+b pro ...

  8. 洛谷P1865 A % B Problem

    1.洛谷P1865 A % B Problem 题目背景 题目名称是吸引你点进来的 实际上该题还是很水的 题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行 ...

  9. 洛谷P1919 【模板】A*B Problem升级版(FFT快速傅里叶)

    题目描述 给出两个n位10进制整数x和y,你需要计算x*y. 输入输出格式 输入格式: 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数为n的正整数y. 输出格式: 输出一 ...

  10. 洛谷 P1001 A+B Problem

    题目描述 输入两个整数a,b,输出它们的和(|a|,|b|<=10^9). 注意 1.pascal使用integer会爆掉哦! 2.有负数哦! 3.c/c++的main函数必须是int类型,而且 ...

随机推荐

  1. Dart 基本语法

    ?? // 如果b为null则赋值,否则保持原样 b ??= value; 级联符号.. querySelector('#confirm') // Get an object. ..text = 'C ...

  2. mysql登录的三种方式

    1.远程登录mysql 先授权:如:grant all on *.* to 'root'@'192.168.81.130' identified by '52033dd';查看是否生效:select ...

  3. 求助,在gmssl中添加第三方库engine的问题

    求助gmssl的一个问题,想知道gmssl怎么添加自己的硬件engine,有搞过的大佬吗,求助.我现在将第三方的sdf标准库,在gmssl的源码中通过gmssl engine尝试添加总是报错libsd ...

  4. 【Deep Learning Nanodegree Foundation笔记】第 9 课:Model Evaluation and Validation

    In this lesson, you'll learn some of the basics of training models. You'll learn the power of testin ...

  5. 【神经网络与深度学习】【Matlab开发】caffe-windows使能Matlab2015b接口

    [神经网络与深度学习][Matlab开发]caffe-windows使能Matlab2015b接口 标签:[神经网络与深度学习] [Matlab开发] 主要是想全部来一次,所以使能了Matlab的接口 ...

  6. css样式,媒体查询,垂直居中,js对象

    下面是一些截图,有关查询效率,css样式,媒体查询,垂直居中,js基本类型.  

  7. Confluence6.9配置邮件服务器

    一.调整confluence服务 1.在confluence安装目录下的server.xml中加一段邮件服务器的配置,加在confluence的Context中 <Context path=&q ...

  8. hive排错

    找出错的那个hive实例,看错误日志: 点下面stdout,找Error

  9. [转帖]黑客通过 Rootkit 恶意软件感染超 5 万台 MS-SQL 和 PHPMyAdmin 服务器

    黑客通过 Rootkit 恶意软件感染超 5 万台 MS-SQL 和 PHPMyAdmin 服务器 https://www.cnbeta.com/articles/tech/852141.htm 病毒 ...

  10. [codeforces1234F]Yet Another Substring Reverse

    题目链接 大致题意为将某个子串进行翻转后,使得不包含相同字符的字符子串长度最长.只能翻转一次或零次. 设一个子串的状态为包含字符的二进制.如子串为$abacd$,则状态为$00000000000000 ...