【UOJ34】高精度乘法(FFT)
题意:


思路:FFT模板,自带10倍常数
type cp=record
x,y:double;
end;
arr=array[..]of cp;
var a,b,cur:arr;
n,m,n1,n2,i,j:longint;
x:double; function jia(a,b:cp;f:longint):cp;
begin
if f=- then
begin
b.x:=-b.x; b.y:=-b.y;
end;
jia.x:=a.x+b.x;
jia.y:=a.y+b.y;
end; function mult(a,b:cp):cp;
begin
mult.x:=a.x*b.x-a.y*b.y;
mult.y:=a.x*b.y+a.y*b.x;
end; procedure swap(var x,y:cp);
var t:cp;
begin
t:=x; x:=y; y:=t;
end; function max(x,y:longint):longint;
begin
if x>y then exit(x);
exit(y);
end; procedure fft(var a:arr;n,f:longint);
var i,j,k,m:longint;
w,u,v:cp; begin
i:=n>>; j:=;
while j<n do
begin
if i<j then swap(a[i],a[j]);
k:=n>>;
while k and i> do
begin
i:=i xor k;
k:=k>>;
end;
i:=i xor k;
inc(j);
end;
m:=;
while m<=n do
begin
w.x:=cos(*pi*f/m); w.y:=sin(*pi*f/m);
cur[].x:=; cur[].y:=;
for i:= to m- do cur[i]:=mult(cur[i-],w);
i:=;
while i<n do
begin
j:=i;
while j<i+(m>>) do
begin
u:=a[j]; v:=mult(a[j+(m>>)],cur[j-i]);
a[j]:=jia(u,v,);
a[j+(m>>)]:=jia(u,v,-);
inc(j);
end;
i:=i+m;
end;
m:=m<<;
end;
end; begin
assign(input,'uoj34.in'); reset(input);
assign(output,'uoj34.out'); rewrite(output);
readln(n1,n2);
inc(n1); inc(n2);
for i:= to n1- do
begin
read(x); a[i].x:=x;
end;
for i:= to n2- do
begin
read(x); b[i].x:=x;
end;
n:=max(n1,n2);
m:=;
while m<=(n<<) do m:=m<<;
fft(a,m,); fft(b,m,);
for i:= to m do a[i]:=mult(a[i],b[i]);
fft(a,m,-);
for i:= to n1+n2- do write(round(a[i].x/m),' ');
close(input);
close(output);
end.
【UOJ34】高精度乘法(FFT)的更多相关文章
- 高精度乘法(FFT)
学会了FFT之后感觉自己征服了世界! 当然是幻觉... 不过FFT还是很有用的,在优化大规模的动规问题的时候有极大效果. 一般比较凶残的计数动规题都需要FFT(n<=1e9). 下面是高精度乘法 ...
- FFT实现高精度乘法
你应该知道$FFT$是用来处理多项式乘法的吧. 那么高精度乘法和多项式乘法有什么关系呢? 观察这样一个$20$位高精度整数$11111111111111111111$ 我们可以把它处理成这样的形式:$ ...
- P1919 FFT加速高精度乘法
P1919 FFT加速高精度乘法 传送门:https://www.luogu.org/problemnew/show/P1919 题意: 给出两个n位10进制整数x和y,你需要计算x*y. 题解: 对 ...
- [vijos P1040] 高精度乘法
如果这次noip没考好,完全是因为从7月29日之后就没有再写过程序了.说起来,真是一个泪流满面的事实… 那这样一个弱智题练手恢复代码能力,竟然还花了我两个晚上(当然不是两整个晚上…) 第一天TLE了, ...
- 【PKU1001】Exponentiation(高精度乘法)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 145642 Accepted: 35529 ...
- hdu 1042 N!(高精度乘法 + 缩进)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...
- hdu 1042 N!(高精度乘法)
Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in ...
- Vijos 1040 高精度乘法
描述 高精度乘法 输入:两行,每行表示一个非负整数(不超过10000位) 输出:两数的乘积. 样例1 样例输入1 99 101 样例输出1 9999 题解 这道题和之前的Vijos 1010 清帝之惑 ...
- 【POJ 1001】Exponentiation (高精度乘法+快速幂)
BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...
- 【BZOJ5300】[CQOI2018]九连环 (高精度,FFT)
[BZOJ5300][CQOI2018]九连环 (高精度,FFT) 题面 BZOJ 洛谷 题解 去这里看吧,多么好 #include<iostream> #include<cstdi ...
随机推荐
- JavaScript--DOM删除节点removeChild()
删除节点removeChild() removeChild() 方法从子节点列表中删除某个节点.如删除成功,此方法可返回被删除的节点,如失败,则返回 NULL. 语法: nodeObject.remo ...
- GIT学习之路最终日 标签管理+总结
本文参考廖雪峰老师的博客进行总结,完整学习请转廖雪峰博客 6.1 创建标签 命令git tag (name)用于新建一个标签,默认为HEAD,也可以指定一个commit id: git tag -a ...
- ACM_蛇形矩阵
蛇行矩阵 Time Limit: 4000/2000ms (Java/Others) Problem Description: 蛇形矩阵是由1开始的自然数依次排列成的一个矩阵上三角形. Input: ...
- eclipse中folder、source folder和package的区别
今天做ssm项目时,突然发现了这个问题,特别好奇,sqlSessionFactory.xml文件如何找到: 1.放在src/hello目录下: InputStream inputStream = Re ...
- 《从Paxos到ZooKeeper 分布式一致性原理与实践》阅读【Leader选举】
从3.4.0版本开始,zookeeper废弃了0.1.2这3种Leader选举算法,只保留了TCP版本的FastLeaderElection选举算法. 当ZooKeeper集群中的一台服务器出现以下两 ...
- Linux学习日记之crontab使用notify-send实现每小时通知提醒
crontab命令用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行 通过crontab -e 可以打开编辑文件添加新的命令 notif ...
- Redux 中的CombineReducer的函数详解
combineReducers(reducers) 随着应用变得复杂,需要对 reducer 函数 进行拆分,拆分后的每一块独立负责管理 state 的一部分. combineReducers 辅助函 ...
- IDEA打可执行jar包
流程: 1. File ->Project Structure -> Artifacts -> + -> JAR -> From modules with depende ...
- Anniversary Cake
Anniversary Cake Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15704 Accepted: 5123 ...
- solr 6.5.1 linux 环境安装
前言 最近在研究搜索引擎,准备搭建一套属于自己的搜索APP,用于搜索的数据我已通过scrapy抓到本地了,现在需要一个搜索引擎来跑这些数据.于是选择了基于Lucene的solr来为我做搜索引擎的工作. ...