HDU1402 A * B Problem Plus
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。
本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!
题目链接:HDU1402
正解:FFT
解题报告:
FFT模板题,注意一下进位处理。
重要的话说三遍:去掉多余的0!!!WA了几遍…
//It is made by ljh2000
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <complex>
using namespace std;
typedef long long LL;
typedef complex<double> C;
const int MAXN = 300011;
const double pi = acos(-1);
char ch[MAXN],s[MAXN];
int n,m,ans[MAXN];
C a[MAXN],b[MAXN]; inline int getint(){
int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
} inline void fft(C *a,int n,int f){
if(n==1) return ;
C a0[n>>1],a1[n>>1],wn(cos(2*pi/n),sin(2*pi*f/n)),w(1,0),t;
for(int i=0;i<n>>1;i++) a0[i]=a[i<<1],a1[i]=a[i<<1|1];
fft(a0,n>>1,f); fft(a1,n>>1,f);
for(int i=0;i<n>>1;i++,w*=wn) {
t=a1[i]*w;
a[i]=a0[i]+t;
a[i+(n>>1)]=a0[i]-t;
}
} inline void work(){
while(scanf("%s",ch)!=EOF) {
scanf("%s",s); memset(ans,0,sizeof(ans));
memset(a,0,sizeof(a)); memset(b,0,sizeof(b));//记得清空!
n=strlen(ch); m=strlen(s); n--; m--;
for(int i=n;i>=0;i--) a[n-i]=(int)ch[i]-'0';
for(int i=m;i>=0;i--) b[m-i]=(int)s[i]-'0';
m+=n; for(n=1;n<=m;n<<=1);
fft(a,n,1); fft(b,n,1);
for(int i=0;i<=n;i++) a[i]*=b[i];
fft(a,n,-1);
for(int i=0;i<=m;i++) ans[i]=(int)(a[i].real()/n+0.5);
for(int i=0;i<=m;i++) ans[i+1]+=ans[i]/10,ans[i]%=10;
while(ans[m+1]>0) m++,ans[m+1]+=ans[m]/10,ans[m]%=10;
while(ans[m]==0) m--;//注意去掉多余的0!!!
if(m>=0) { for(int i=m;i>=0;i--) printf("%d",ans[i]); puts(""); }
else puts("0");
}
} int main()
{
work();
return 0;
}
HDU1402 A * B Problem Plus的更多相关文章
- FFT/NTT模板 既 HDU1402 A * B Problem Plus
@(学习笔记)[FFT, NTT] Problem Description Calculate A * B. Input Each line will contain two integers A a ...
- hdu----(1402)A * B Problem Plus(FFT模板)
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU1402 A * B Problem Plus(FFT)
http://acm.hdu.edu.cn/showproblem.php?pid=1402 初学FFT. http://www.cnblogs.com/WABoss/p/FFT_Note.html ...
- HDU1402 A * B Problem Plus FFT
分析:网上别家的代码都分析的很好,我只是给我自己贴个代码,我是kuangbin的搬运工 一点想法:其实FFT就是快速求卷积罢了,当小数据的时候我们完全可以用母函数来做,比如那种硬币问题 FFT只是用来 ...
- HDU-1402 A * B Problem Plus FFT(快速傅立叶变化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 一般的的大数乘法都是直接模拟乘法演算过程,复杂度O(n^2),对于这题来说会超时.乘法的过程基本 ...
- 【NTT】hdu1402 A * B Problem Plus
r·2^k+1 r k g 3 1 1 2 5 1 2 2 17 1 4 3 97 3 5 5 193 3 6 5 257 1 8 3 7681 15 9 17 12289 3 12 11 40961 ...
- 【FFT】hdu1402 A * B Problem Plus
FFT板子. 将大整数看作多项式,它们的乘积即多项式的乘积在x=10处的取值. #include<cstdio> #include<cmath> #include<cst ...
- [hdu1402]A * B Problem Plus(NTT)
解题关键:快速数论变换NTT模板. 注意$ans$数组的$ans[n]$一定要注意置$0$,或者结果从$n-1$开始遍历,这里很容易出错. 代码1:ACdreamer 的板子. 为什么要reverse ...
- [hdu1402]A * B Problem Plus(FFT模板题)
解题关键:快速傅里叶变换fft练习. 关于结果多项式长度的确定,首先将短多项式扩展为长多项式,然后扩展为两倍. #include<cstdio> #include<cstring&g ...
随机推荐
- 爬虫入门【11】Pyspider框架入门—使用HTML和CSS选择器下载小说
开始之前 首先我们要安装好pyspider,可以参考上一篇文章. 从一个web页面抓取信息的过程包括: 1.找到页面上包含的URL信息,这个url包含我们想要的信息 2.通过HTTP来获取页面内容 3 ...
- ZOJ 1648 Circuit Board(计算几何)
Circuit Board Time Limit: 2 Seconds Memory Limit: 65536 KB On the circuit board, there are lots of c ...
- fineReport---sql
一.开窗函数-逐层平均 在创建数据集时用sql的开窗排名函数[AVG(字段) over(PARTITION BY 分组字段 order by 逐层字段)]处理,然后进行直接调用. 详细说明 二.开窗函 ...
- 第13章—数据库连接池(Druid)
spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...
- MyBatis 之动态SQL
1. 概述 动态 SQL 极大的简化了我们拼装SQL的操作; MyBatis 采用功能强大的基于 OGNL 的表达式来简化操作: if choose(when,otherwise) trim(wher ...
- pandas删除包含指定内容的行
Outline 处理数据时,遇到文件中包含一些不需要的数据(行),需要把这些不符合要求的行给删除掉. 例如:该数据中应该都是2000年的数据,但是包含了一些2001年的数据,所以需要把2001年的数据 ...
- 使用win32ole进行页面加载和跳转
require "win32ole" #包含库 ie = WIN32OLE.new('internetExplorer.Application') ie.visible = tru ...
- Python3+Selenium3自动化测试-(一)
完成环境的安装并测试之后,我们对Selenium有了一定的了解了,接下来我们继续驱动浏览器做一些基本操作: 窗口尺寸设置.网页截图.刷新.前进和后退 窗口尺寸设置 在测试过程中,我们可能会要求打开浏览 ...
- 利用EasySQLMAIL实现自动填写Excel表格并发送邮件(2)
利用EasySQLMAIL实现自动填写Excel表格并发送邮件 转自:http://blog.sina.com.cn/s/blog_1549483b70102witg.html 前一篇博文中记录了“利 ...
- Android图片加载框架Picasso最全使用教程2
前言 前面我们已经介绍了Picasso的基本用法及如何将一张图片加载到ImageView中,下面我们就利用Picasso在ListView中加载图片;Let’s Go! 一个ListView的简单应用 ...