题意:打高尔夫 给你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)的更多相关文章

  1. UVALive 6886 Golf Bot FFT

    Golf Bot 题目连接: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=129724 Description Do ...

  2. Gym 100783C Golf Bot FFT

    大致题意: 给你N个整数和M个整数,问这M个数中,有几个数可以表达成那N个整数中一个或者两个整数的和. 分析: 算是半个裸的FFT.FFT可以用来在nlongn时间内求高精度乘法,我们先模拟一下乘法. ...

  3. LA6886 Golf Bot(FFT)

    题目 Source https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page= ...

  4. UVALive - 6886 Golf Bot 多项式乘法(FFT)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/129724 Golf Bot Time Limit: 15000MS 题意 给你n个数,m个查询,对于每个查询 ...

  5. HNU11376:Golf Bot

    Problem description Input The first line has one integer: N, the number of different distances the G ...

  6. Gym100783C Golf Bot(FFT)

    https://vjudge.net/problem/Gym-100783C 题意: 给出n个数,然后有m次查询,每次输入一个数x,问x能否由n个数中2个及2个以下的数相加组成. 思路:题意很简单,但 ...

  7. [Swerc2014 C]Golf Bot

    题意:给你N个数字,每次利用这N个数字中最多两个数字进行加法运算,来得到目标中的M个数字. Solution: 我们先来看看多项式乘法:\(A(x)=\sum_{i=0}^{n-1}a_ix^i\), ...

  8. FFT题集

    FFT学习参考这两篇博客,很详细,结合这看,互补. 博客一 博客二 很大一部分题目需要构造多项式相乘来进行计数问题. 1. HDU 1402 A * B Problem Plus 把A和B分别当作多项 ...

  9. 并行计算提升32K*32K点(32位浮点数) FFT计算速度(4核八线程E3处理器)

    对32K*32K的随机数矩阵进行FFT变换,数的格式是32位浮点数.将产生的数据存放在堆上,对每一行数据进行N=32K的FFT,记录32K次fft的时间. 比较串行for循环和并行for循环的运行时间 ...

随机推荐

  1. Python爬虫开发【第1篇】【urllib2】

    1.urlopen # urllib2_urlopen.py # 导入urllib2 库 import urllib2 # 向指定的url发送请求,并返回服务器响应的类文件对象,urlopen中有da ...

  2. PNG vs. GIF vs. JPEG vs. SVG - When best to use?

    image - PNG vs. GIF vs. JPEG vs. SVG - When best to use? - Stack Overflow https://stackoverflow.com/ ...

  3. update-java-alternatives 更改默认Java环境

    Ubuntu/debian 更改默认Java环境 我的电脑里安装了两个版本的Java,一个是java-6-sun,还有一个是java-gcjgcj是在JVM非常缓慢的时候诞生的,他可以把Java代码编 ...

  4. 玲珑学院OJ 1028 - Bob and Alice are playing numbers 字典树,dp

    http://www.ifrog.cc/acm/problem/1028 题解处:http://www.ifrog.cc/acm/solution/4 #include <cstdio> ...

  5. bzoj1085 [SCOI2005]骑士精神——IDA*

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1085 搜索,IDA*,估价就是最少需要跳的步数: 代码意外地挺好写的,memcmp 用起来好 ...

  6. bzoj3670 [Noi2014]动物园——KMP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3670 第一次写KMP算法...又T又WA了半天... 1. num 数组表示包括其本身的前缀 ...

  7. nginx开发(二)配置mp4文件在线播放

    1: 第一步先开打nginx的文件夹遍历功能 vi /usr/local/nginx/conf/nginx.conf #编辑配置文件,在http {下面添加以下内容: autoindex on; #开 ...

  8. 重装Eclipse 往其中加Python插件时 遇到不能独立运行c c++ python 代码时修改办法:

    鼠标移动到新建项目处 ,右键->run as-> run configuration->选择Enable auto build 即可.

  9. CodeForces 515C Drazil and Factorial (水题)

    题意:给出含有 n 个只有阿拉伯数字的字符串a,设定函数F(a) = 每个数字的阶乘乘积 .需要找出 x,使得F(x) = F(a),且组成 x 的数字中没有0和1.求最大的 x 为多少. 析:最大, ...

  10. JS中定时器的返回数值ID值

    定时器会返回一个数字值id,可以由clearInterval(id)或clearTimeout(id)来实现对对应定时器的清除. setInterval()/setTimeout()BOM中的Wind ...