UVALIVE6886 Golf Bot (FFT)
题意:打高尔夫 给你n个距离表示你一次可以把球打远的距离
然后对于m个询问 问能否在两杆内把球打进洞
题解:平方一下就好 注意一下x0的系数为1表示打一杆
才发现数组应该开MAXN * 4 之前写的题数据有点不严谨了
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-; struct Complex
{
double x, y;
Complex(double _x = 0.0, double _y = 0.0)
{
x = _x;
y = _y;
}
Complex operator + (const Complex &b) const
{
return Complex(x + b.x, y + b.y);
}
Complex operator - (const Complex &b) const
{
return Complex(x - b.x, y - b.y);
}
Complex operator * (const Complex &b) const
{
return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
}
}; void change(Complex y[], int len)
{
int i, j, k;
for(i = , j = len / ; i < len - ;i++)
{
if(i < j) swap(y[i], y[j]);
k = len / ;
while(j >= k)
{
j -= k;
k /= ;
}
if(j < k) j += k;
}
} void fft(Complex y[], int len, int on)
{
change(y, len);
for(int h = ; h <= len; h <<= )
{
Complex wn(cos(-on * * PI / h), sin(-on * * PI / h));
for(int j = ; j < len; 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;
}
}
}
if(on == -)
for(int i = ; i < len; i++)
y[i].x /= len;
} Complex x1[]; int main()
{
int n, m;
while(~scanf("%d", &n))
{
int zd = ;
for(int i = ; i <= ; i++) x1[i] = Complex(, );
for(int i = ; i <= n; i++)
{
int x; scanf("%d", &x);
zd = max(zd, x);
x1[x] = Complex(, );
}
x1[] = Complex(, ); int len = ;
while(len < zd + ) len <<= ;
len <<= ;
for(int i = zd + ; i < len; i++) x1[i] = Complex(, ); fft(x1, len, );
for(int i = ; i < len; i++) x1[i] = x1[i] * x1[i];
fft(x1, len, -); scanf("%d", &m);
int ans = ;
for(int i = ; i <= m; i++)
{
int xx; scanf("%d", &xx);
if(fabs(x1[xx].x) > eps) ans++;
}
printf("%d\n", ans);
}
return ;
}
UVALIVE6886 Golf Bot (FFT)的更多相关文章
- UVALive 6886 Golf Bot FFT
Golf Bot 题目连接: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=129724 Description Do ...
- Gym 100783C Golf Bot FFT
大致题意: 给你N个整数和M个整数,问这M个数中,有几个数可以表达成那N个整数中一个或者两个整数的和. 分析: 算是半个裸的FFT.FFT可以用来在nlongn时间内求高精度乘法,我们先模拟一下乘法. ...
- LA6886 Golf Bot(FFT)
题目 Source https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page= ...
- UVALive - 6886 Golf Bot 多项式乘法(FFT)
题目链接: http://acm.hust.edu.cn/vjudge/problem/129724 Golf Bot Time Limit: 15000MS 题意 给你n个数,m个查询,对于每个查询 ...
- HNU11376:Golf Bot
Problem description Input The first line has one integer: N, the number of different distances the G ...
- Gym100783C Golf Bot(FFT)
https://vjudge.net/problem/Gym-100783C 题意: 给出n个数,然后有m次查询,每次输入一个数x,问x能否由n个数中2个及2个以下的数相加组成. 思路:题意很简单,但 ...
- [Swerc2014 C]Golf Bot
题意:给你N个数字,每次利用这N个数字中最多两个数字进行加法运算,来得到目标中的M个数字. Solution: 我们先来看看多项式乘法:\(A(x)=\sum_{i=0}^{n-1}a_ix^i\), ...
- FFT题集
FFT学习参考这两篇博客,很详细,结合这看,互补. 博客一 博客二 很大一部分题目需要构造多项式相乘来进行计数问题. 1. HDU 1402 A * B Problem Plus 把A和B分别当作多项 ...
- 并行计算提升32K*32K点(32位浮点数) FFT计算速度(4核八线程E3处理器)
对32K*32K的随机数矩阵进行FFT变换,数的格式是32位浮点数.将产生的数据存放在堆上,对每一行数据进行N=32K的FFT,记录32K次fft的时间. 比较串行for循环和并行for循环的运行时间 ...
随机推荐
- [办公自动化]名师推荐-excelpro刘万祥 图表之道作者
最早认识刘万祥老师是通过孙小小老师的博客.后来发现制作图表,还真需要和PPT类似,花些时间琢磨一下. 首先你要了解图表的类型,然后需要了解制作方法,最后就是如何美化以及结合PPT等工具帮你分析数据. ...
- gitlab的安装和配置
1 使用omnibus gitlab来安装gitlab 也就是说,将gitlab和它所需要的组件打一个包,即打一个bundle进行安装. 第一步,安装gitlab的源. curl https://pa ...
- 【Codeforces】665E Beautiful Subarrays
E. Beautiful Subarrays time limit per test: 3 seconds memory limit per test: 512 megabytes input: st ...
- c# 生成 xml 文件
方法一: using System; using System.Xml; using System.IO; using System.Text; public class ReadWriteXml { ...
- mybatis批量update操作的写法,及批量update报错的问题解决方法
mybatis的批量update操作写法很简单,如下: public interface YourMapper extends BaseMapper<YourExt> { void upd ...
- Linux查找和替换目录下所有文件中字符串(转载)
转自:http://rubyer.me/blog/1613/ 单个文件中查找替换很简单,就不说了.文件夹下所有文件中字符串的查找替换就要记忆了,最近部署几十台linux服务器,记录下总结. 查找文件夹 ...
- sshfs把远程主机的文件系统映射到本地的目录中(转载)
转自:http://www.fwolf.com/blog/post/329 windows之外的世界比想像中要大得多呢,几乎天天都在用ssh,却到今天才知道有sshfs这个好东西,前几天还在为Zend ...
- mysql workbench的简单使用
注意:即使server没有开启,也可以通过workbench进来编辑页面. 1.再开始程序找到mysql workbench,点击运行 2.t添加管理员链接mysql-------------前提是你 ...
- bzoj 1673: [Usaco2005 Dec]Scales 天平【dfs】
真是神奇 根据斐波那契数列,这个a[i]<=c的最大的i<=45,所以直接搜索即可 #include<iostream> #include<cstdio> usin ...
- Winform执行CMD命令
1.首先分享CmdHelper类: using System; using System.Collections.Generic; using System.Text; using System.Di ...