A * B Problem Plus

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22082    Accepted Submission(s): 5511

Problem Description

Calculate A * B.
 

Input

Each line will contain two integers A and B. Process to end of file.

Note: the length of each integer will not exceed 50000.

 

Output

For each case, output A * B in one line.
 

Sample Input

1
2
1000
2
 

Sample Output

2
2000
 

Author

DOOM III
 
 //2017-09-07
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <complex>
#include <cmath>
#define Complex complex<double> using namespace std; const double PI = acos(-1.0);
const int N = ; void fft(Complex y[], int n, int op){
for(int i = , j = n/; i < n-; i++){
if(i<j)swap(y[i], y[j]);
int k = n/;
while(j >= k){
j -= k;
k /= ;
}
if(j<k)j += k;
}
for(int h = ; h <= n; h <<= ){
Complex wn(cos(-op**PI/h), sin(-op**PI/h));
for(int j = ; j < n; j += h){
Complex w(, );
for(int k = j; k < j+h/; k++){
Complex u = y[k];
Complex t = w*y[k+h/];
y[k] = u+t;
y[k+h/] = u-t;
w = w*wn;
}
}
}
} char a[N], b[N];
Complex A[N<<], B[N<<];
int ans[N<<];
void poly_muilt(){
int n = , len1 = strlen(a), len2 = strlen(b);
while(n<len1* || n<len2*)n<<=;
for(int i = ; i < len1; i++)A[i] = a[len1-i-]-'';
for(int i = len1; i < n; i++)A[i] = ;
for(int i = ; i < len2; i++)B[i] = b[len2-i-]-'';
for(int i = len2; i < n; i++)B[i] = ;
fft(A, n, );
fft(B, n, );
for(int i = ; i < n; i++)
A[i] *= B[i];
fft(A, n, -);
for(int i = ; i < n; i++)
ans[i] = (int)(A[i].real()/n+0.5);
for(int i = ; i < n; i++){
ans[i+] += ans[i]/;
ans[i] %= ;
}
n = len1+len2-;
while(ans[n] <= && n > )n--;
for(int i = n; i >= ; i--)
printf("%c", ans[i]+'');
printf("\n");
} int main()
{
while(scanf("%s%s", a, b) != EOF){
poly_muilt();
} return ;
}

HDU1402(fft)的更多相关文章

  1. 快速傅里叶(FFT)的快速深度思考

    关于按时间抽取快速傅里叶(FFT)的快速理论深度思考 对于FFT基本理论参考维基百科或百度百科. 首先谈谈FFT的快速何来?大家都知道FFT是对DFT的改进变换而来,那么它究竟怎样改进,它改进的思想在 ...

  2. 【BZOJ3527】力(FFT)

    [BZOJ3527]力(FFT) 题面 Description 给出n个数qi,给出Fj的定义如下: \[Fj=\sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{ ...

  3. 【BZOJ4827】【HNOI2017】礼物(FFT)

    [BZOJ4827][HNOI2017]礼物(FFT) 题面 Description 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每 ...

  4. FFT/NTT总结+洛谷P3803 【模板】多项式乘法(FFT)(FFT/NTT)

    前言 众所周知,这两个东西都是用来算多项式乘法的. 对于这种常人思维难以理解的东西,就少些理解,多背板子吧! 因此只总结一下思路和代码,什么概念和推式子就靠巨佬们吧 推荐自为风月马前卒巨佬的概念和定理 ...

  5. 【BZOJ4503】两个串(FFT)

    [BZOJ4503]两个串(FFT) 题面 给定串\(S\),以及带通配符的串\(T\),询问\(T\)在\(S\)中出现了几次.并且输出对应的位置. \(|S|,|T|<=10^5\),字符集 ...

  6. 【BZOJ4259】残缺的字符串(FFT)

    [BZOJ4259]残缺的字符串(FFT) 题面 给定两个字符串\(|S|,|T|\),两个字符串中都带有通配符. 回答\(T\)在\(S\)中出现的次数. \(|T|,|S|<=300000\ ...

  7. 【51Nod1258】序列求和V4(FFT)

    [51Nod1258]序列求和V4(FFT) 题面 51Nod 多组数据,求: \[Ans=\sum_{i=1}^ni^k,n\le 10^{18},k\le50000\] 题解 预处理伯努利数,时间 ...

  8. 【CF528D】Fuzzy Search(FFT)

    [CF528D]Fuzzy Search(FFT) 题面 给定两个只含有\(A,T,G,C\)的\(DNA\)序列 定义一个字符\(c\)可以被匹配为:它对齐的字符,在距离\(K\)以内,存在一个字符 ...

  9. 【CF954I】Yet Another String Matching Problem(FFT)

    [CF954I]Yet Another String Matching Problem(FFT) 题面 给定两个字符串\(S,T\) 求\(S\)所有长度为\(|T|\)的子串与\(T\)的距离 两个 ...

随机推荐

  1. C语言Socket-单工通信(客户端向服务器发送数据)

    服务端(server) #include <stdio.h> #include <winsock2.h> #pragma comment(lib,"ws2_32.li ...

  2. LOJ#3048. 「十二省联考 2019」异或粽子(trie树+堆)

    题面 传送门 题解 我们先把它给前缀异或和一下,然后就是要求前\(k\)大的\(a_i\oplus a_j\).把\(k\)乘上个\(2\),变成前\(2k\)大的\(a_i\oplus a_j\), ...

  3. tomcat单机多实例部署

    最近在面试的过程中,一家公司在面试时提到了有关tomcat单机多实例部署的提问, 正好, 之前使用IntelliJ IDEA 13.1.4这款IDE开发web项目,在开发的过程中,因为有多个web项目 ...

  4. ubuntu下nodejs源码安装

    1.从github选择下载自己要安装的nodejs版本,https://github.com/nodejs/node/releases,我下载的版本是node-9.11.2.tar.gz 2.解压no ...

  5. underscore.js源码研究(7)

    概述 很早就想研究underscore源码了,虽然underscore.js这个库有些过时了,但是我还是想学习一下库的架构,函数式编程以及常用方法的编写这些方面的内容,又恰好没什么其它要研究的了,所以 ...

  6. 【文档】使用Sphinx + reST编写文档

    0 前言 写文档是开发人员日常工作中的一项重要内容,除了word之外,我更偏爱使用标记语言(Markup Language).使用标记语言,可以利用简单.免费的文本编辑器(记事本,vim, emacs ...

  7. How To Crop Bitmap For UWP

    裁剪图片主要是借助于 BitmapDecoder.GetPixelDataAsync() 以及 BitmapTransform对象来实现. 实现的代码如下: using System; using S ...

  8. sftp命令不被识别

    sftp命令不被识别 原因:C:\Windows\System32文件夹下面没有sftp可执行程序 解决方案:安装openssh,安装完成之后可发现在path系统变量的值中多了openssh的安装目录 ...

  9. Android面试题(2)

    1.  int 和 Integer 有什么区别 Java 提供两种不同的类型:引用类型和原始类型(或内置类型).Int是java的原始数据类型,Integer是java为int提供的封装类.Java为 ...

  10. 优先队列/oriority queue 之最大优先队列的实现

    优先队列(priority queue)是一种用来维护一组数据集合S的数据结构.每一个元素都有一个相关的值,被称为关键字key. 这里以实现最大优先队列为例子 最大优先队列支持的操作如下:INSERT ...