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循环的运行时间 ...
随机推荐
- CentOS 7 执行级别的切换
CentOS 7 执行级别的切换 由命令行级别切换到窗体级别的命令未变:init 5或startx 由窗体级别切换到命令行级别的命令未变:init 3 新版本号的执行级别都定义在 /lib/syste ...
- mysql数据库批量高速插入
近期在处理一批数据,须要从库中表里的字段进行处理然后导出到一个新表中.只是这个表的数据量有近500w条. 这数据量出现的的问题是须要处理的时间好长. 首先想到,一句一句的插入,大数据量处理时间好长,忽 ...
- SGU 261. Discrete Roots (N次剩余)
N次剩余 题目:http://acm.sgu.ru/problem.php? contest=0&problem=261 题意:给定n,a,p 求出x^n ≡ a(mod p)在模p意义下的全 ...
- Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip 树形压位DP
题目链接:http://codeforces.com/contest/766/problem/E Examples input 3 1 2 3 1 2 2 3 out 10 题意: 给你一棵n个点 ...
- 网络流之最大流算法(EK算法和Dinc算法)
最大流 网络流的定义: 在一个网络(有流量)中有两个特殊的点,一个是网络的源点(s),流量只出不进,一个是网络的汇点(t),流量只进不出. 最大流:就是求s-->t的最大流量 假设 u,v 两个 ...
- Java 相关计数问题及其实现
数(三声)数(四声)问题自然使用非负整数: 0. 一个类作为一个计数器 java 语法 -- final class Counter { private static long counter; pr ...
- nginx开发(二)配置mp4文件在线播放
1: 第一步先开打nginx的文件夹遍历功能 vi /usr/local/nginx/conf/nginx.conf #编辑配置文件,在http {下面添加以下内容: autoindex on; #开 ...
- 7章 Admin
Admin这个东西本身就已经存在于我们的项目中,是Django自己创建的.admin是Django自带的一个APP. # Application definition INSTALLED_APPS = ...
- jQuery 表格隔行变色插件
jQuery提供了用于扩展jQuery功能的方法,即jQuery.fn.extend()方法和jQuery.extend()方法. 基本的JS框架代码如下: ;(function($) { $.fn. ...
- 04-Vue中的动画
Vue中的动画 为什么要有动画:动画能够提高用户的体验,帮助用户更好的理解页面中的功能: -使用过渡类名 1.html <div id="app"> <input ...