题意:打高尔夫 给你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. u

    Atrrible /s/d –s –h  u盘修复

  2. 李洪强iOS开发之动态获取UILabel的bounds

    李洪强iOS开发之动态获取UILabel的bounds 在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法. 1.获取宽度,获取字符串不折行单行显示时所需 ...

  3. MyEclipse+Tomcat+MAVEN+SVN项目完整环境搭建

    这次换了台电脑,所以须要又一次配置一次项目开发环境,过程中的种种,记录下来,便于以后再次安装.同一时候给大家一个參考. 1.JDK的安装 首先下载JDK,这个从sun公司官网能够下载.依据自己的系统选 ...

  4. nginxserver报403 forbidden错误的解决的方法

     改动nginx.config文件内容: location / {             #root   html;             root   D:\java;            ...

  5. JavaScript基础 -- 常见DOM树操作

    1.创建并增加元素节点 <ul id="ul"> <li>1</li> <li>2</li> <li>3&l ...

  6. ios22--动画

    控制器: // // ViewController.m // 07-渐变动画 // // Created by xiaomage on 15/12/30. // Copyright © 2015年 小 ...

  7. 【T^T 1871】获取敌情

    获取敌情 在公元4484年,人类展开了对外界星球的征途和探索,但也不可避免的展开了和外星人之间的战争.偶然的机遇之下,美国联邦调查局截获了一串来自外星球的信息.但不知道有什么特殊的意义.所以就委托你, ...

  8. continue 的理解

    continue 一般出现循环体的开始部分,或中间部分,而不可能是结尾(没有必要,正常执行也会退出本次循环): 1. continue 的替代方案 while (true){ if (A || B){ ...

  9. missing required source folder

    Eclipse 中XXX is missing required source folder 问题的解决 https://blog.csdn.net/itzhangdaopin/article/det ...

  10. 洛谷P1291 [SHOI2002]百事世界杯之旅——期望DP

    题目:https://www.luogu.org/problemnew/show/P1291 水水的经典期望DP: 输出有毒.(其实也很简单啦) 代码如下: #include<iostream& ...