哇。。fft的原理真的是不太好懂,看了好久许多细节还是不太清楚,但感觉本质就是用了单位根的性质。

https://www.luogu.org/problem/P1919

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<complex>
using namespace std;
int n;
typedef complex<double> cd;
#define maxl 2097153
#define PI 3.14159265358979
char s1[maxl],s2[maxl];
cd a[maxl];
cd b[maxl];
int rev[maxl];
void get_rev(int bit)
{
for(int i=0;i<(1<<bit);i++)
rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
}
void fft(cd *a,int n,int dft)
{
for(int i=0;i<n;i++) if(i<rev[i]) swap(a[i],a[rev[i]]);
for(int step=1;step<n;step<<=1)
{
cd wn=exp(cd(0,dft*PI/step));
for(int j=0;j<n;j+=step<<1)
{
cd wnk(1,0);
for(int k=j;k<j+step;k++)
{
cd x=a[k];
cd y=wnk*a[k+step];
a[k]=x+y;
a[k+step]=x-y;
wnk*=wn;
}
}
}
if(dft==-1) for(int i=0;i<n;i++) a[i]/=n;
}
int output[maxl];
int main()
{
//freopen("fft.in","r",stdin);
scanf("%s%s",s1,s2);
int l1=strlen(s1);
int l2=strlen(s2);
int s=2,bit=1;
for(bit=1;(1<<bit)<l1+l2-1;bit++)s<<=1;//maybe wiping the"-1" is better
for(int i=0;i<l1;i++) a[i]=(double)(s1[l1-i-1]-'0');
for(int i=0;i<l2;i++) b[i]=(double)(s2[l2-i-1]-'0');
//for(int i=0;i<8;i++) printf("%d %d\n",i,rev[i]);
get_rev(bit);
fft(a,s,1);
fft(b,s,1);
for(int i=0;i<s;i++) a[i]*=b[i];
fft(a,s,-1);
for(int i=0;i<s;i++)
{
output[i]+=(int)(a[i].real()+0.5);//取实数四舍五入,此时虚数部分应当为0或由于浮点误差接近0
output[i+1]+=output[i]/10;
output[i]%=10;
}
int i;
for(i=l1+l2;!output[i]&&i>=0;i--);
if(i==-1) printf("0");
for(;i>=0;i--) printf("%d",output[i]);
putchar('\n');
}

高精乘(fft板子的更多相关文章

  1. maomao的fft板子

    \(QwQ\) #include <cmath> #include <cstdio> #include <cstring> #include <iostrea ...

  2. jzoj6005. 【PKUWC2019模拟2019.1.17】数学 (生成函数+FFT+抽代+高精)

    题面 题解 幸好咱不是在晚上做的否则咱就不用睡觉了--都什么年代了居然还会出高精的题-- 先考虑如果暴力怎么做,令\(G(x)\)为\(F(n,k)\)的生成函数,那么不难发现\[G^R(x)=\pr ...

  3. bzoj 3287: Mato的刷屏计划 高精水题 && bzoj AC150

    3287: Mato的刷屏计划 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 124  Solved: 43[Submit][Status] Desc ...

  4. bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】

    高精乘法板子 然而WA了两次也是没救了 #include<iostream> #include<cstdio> #include<cstring> using na ...

  5. 「NOIP模拟赛」数位和乘积(dp,高精)

    统计方案数,要么组合数,要么递推(dp)了. 这是有模拟赛历史以来爆炸最狠的一次 T1写了正解,也想到开long long,但是开错了地方然后数组开大了结果100->0 T3看错题本来简单模拟又 ...

  6. Linux 高精確的時序(sleep, usleep,nanosleep) from:http://blog.sina.com.cn/s/blog_533ab41c0100htae.html

    Linux 高精確的時序(sleep, usleep,nanosleep) (2010-04-14 17:18:26) 转载▼ 标签: 杂谈 分类: linux 首先, 我会说不保证你在使用者模式 ( ...

  7. c++ 普通高精除高精

    //codevs3118 高精度练习之除法 //打出了高精除高精,内心有点小激动. //还记得已开始学的时候非常难打 #include<cstdio>#include<cstring ...

  8. c++普通高精加

    //作为一名蒟蒻,还请诸位不要吐槽. //第一次打c++高精加,内心有点小激动. //为codevs3116 高精度练习之加法 //程序太简单,就不打注释了. #include<cstdio&g ...

  9. BZOJ_1002_[FJOI2007]_轮状病毒_(递推+高精)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1002 )*&*(^&*^&*^**()*) 1002: [FJOI20 ...

  10. codevs 3119 高精度练习之大整数开根 (各种高精+压位)

    /* codevs 3119 高精度练习之大整数开根 (各种高精+压位) 二分答案 然后高精判重 打了一个多小时..... 最后还超时了...压位就好了 测试点#1.in 结果:AC 内存使用量: 2 ...

随机推荐

  1. AC自动机2

    AC自动机 给N个模式串,求文本串中出现次数最多的模式串出现次数. #include<bits/stdc++.h> using namespace std; #define maxn 10 ...

  2. jQuery实现三级联动菜单(鼠标悬停联动)

    效果图: 代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> < ...

  3. leetcode-mid-array-49 Group Anagrams

    mycode  95.35% 思路:构建字典 class Solution(object): def groupAnagrams(self, strs): """ :ty ...

  4. Linux内核调试方法总结之调试宏

    本文介绍的内核调试宏属于静态调试方法,通过调试宏主动触发oops从而打印出函数调用栈信息. 1) BUG_ON 查看bug处堆栈内容,主动制造oops Linux中BUG_ON,WARN_ON用于调试 ...

  5. 认识DOM(上)

    认识DOM 文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM 将HTML文档呈现为带有元素.属性和文本的树结构(节点树). 先来看看下面代码 ...

  6. Maven install报错:MojoFailureException ,To see the full stack trace of the errors, re-run Maven with the -e switch.解决

    报错日志: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to ...

  7. 《Using Databases with Python》Week1 Object Oriented Python 课堂笔记

    Coursera课程<Using Databases with Python> 密歇根大学 Charles Severance Week1 Object Oriented Python U ...

  8. dvorak键盘布局调整

    一站直达: http://www.kaufmann.no/roland/dvorak/

  9. Nginx配置之rewrite、proxy_pass、upstream、location

    如图,这是Nginx的配置文件nginx.conf中的一段配置代码. 在http段中定义了一个名为webservers的upstream模块,主要用于负载均衡. 在server模块中,定义了一个loc ...

  10. C语言作业总结

    .## 一.我学到的内容 二.我的收获 作业 学到的知识点简介 C语言I博客作业01 学习了markdown语法. C语言I博客作业02 学习了<提问的智慧>. C语言I博客作业03 了解 ...