UVALive6886 Golf Bot[FFT]

达梦的自定义类型和存储过程支持创建同义词,不支持同义词使用? 达梦8的自定义类型和存储过程支持创建同义词,但是通过同义词调用报错,而在oracle上验证没有问题,难道是发现了达梦的bug了?非也非也,详情请见下文 阅读详情

M - Golf Bot

  UVALive - 6886 

Do you like golf? I hate it. I hate golf so much that I decided tobuild the ultimate golf robot, a robot that will never miss a shot. I simplyplace it over the ball, choose the right direction and distance and,flawlessly, it will strike the ball across the air and into the hole. Golf willnever be played again.

Unfortunately, it doesn’t work as planned. So, here I am, standingin the green and preparing my first strike when I realize that thedistance-selector knob built-in doesn’t have all the distance options! Noteverything is lost, as I have 2 shots.

Given my currentrobot, how many holes will I be able to complete in 2 strokes or less? The ballmust be always on the right line between the tee and the hole. It isn’t allowedto overstep it and come back.

Input

The input file contains several testcases, each of them as described below.

The first line has oneinteger: N, the number of differentdistances the Golf Bot can shoot. Each of the followingNlines has one integer,ki,the distance marked in positioniofthe knob.

Next line has one integer: M,the number of holes in this course. Each of the followingMlines has one integer,dj,the distance from Golf Bot to holej.

Constraints:

1 ≤ N,M≤ 200000

1 ≤ ki,dj≤ 200000

Output

For each testcase, you should output a single integer, the number of holes Golf Bot will beable to complete. Golf Bot cannot shoot over a hole on purpose and then shootbackwards.

Sample Output Explanation

Golf Bot can shoot 3different distances (1, 3 and 5) and there are 6 holes in this course atdistances 2, 4, 5, 7, 8 and 9. Golf Bot will be able to put the ball in 4 ofthese:

•   The 1st hole, at distance 2, can be reached by striking twotimes a distance of 1.

•   The 2nd hole, at distance 4, can be reached by striking withstrength 3 and then strength 1 (or vice-versa).

•   The 3rd hole can be reached with just one stroke of strength5.

•   The 5th hole can be reached with two strikes of strengths 3and 5.

Holes 4 and 6 can never be reached.

Sample Input

3

1

3

5

6

2

4

5

7

8

9

Sample Output

4


题意:

给出一个n,接下来给出n个数,再给一个m,询问m中有多少个数能由1个或者2个所给的n个数中的数构成。(可重复使用)


题解:

FFT入门题。

可以题目所给的k不超过2e5,那么我们就可以把他列为多项式。

例如样例  可以列为 
那么他两两组合(包括自身跟自身组合)就是

运用FFT算出多项式乘积的结果。

那么我们就可以得出

当然,这只是两两组合的结果(这个多项式的结果是按组合顺序的,所以会重复计算了不同的两项组合的次数)

那么如果D[i]中有等于K[j]的,同样符合结果。

所以多项式上加上

再去判断共有多少个D[i]能被组合出来。


为了学FFT 去看了一些博客。

如果有兴趣的 可以去看看(T_T虽然我看了好久才看懂)

http://www.gatevin.moe/acm/fft%E7%AE%97%E6%B3%95%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/

https://oi.men.ci/fft-notes/


#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int M=1<<20;
const double PI=acos(-1.0);
int K[N],D[N],num[N];
ll ans[M];
struct Complex
{
    double real,image;
    Complex(double r=0.0,double i=0.0):real(r),image(i){};
    Complex operator + (const Complex &b)
    {
        return Complex(real+b.real,image+b.image);
    }
    Complex operator - (const Complex &b)
    {
        return Complex(real-b.real,image-b.image);
    }
    Complex operator * (const Complex &b)
    {
        return Complex(real*b.real-image*b.image,image*b.real+real*b.image);
    }
}x[M];
void change(Complex x[],int len)
{
    for (int i=1,j=len/2 ; i<len-1 ; ++i)
    {
        if (i<j)
            swap(x[i],x[j]);
        int k=len/2;
        while (j>=k)
        {
            j-=k;
            k/=2;
        }
        if (j<k)
            j+=k;
    }
}
void FFT(Complex x[],int len,int dft)
{
    change(x,len);
    for (int h=2 ; h<=len ; h<<=1)
    {
        Complex wn(cos(dft*2*PI/h),sin(dft*2*PI/h));
        for (int j=0 ; j<len ; j+=h)
        {
            Complex w(1,0);
            for (int k=j ; k<j+h/2 ; ++k)
            {
                Complex u=x[k];
                Complex t=w*x[k+h/2];
                x[k]=u+t;
                x[k+h/2]=u-t;
                w=w*wn;
            }
        }
    }
    if (dft==-1)
    {
        for (int i=0 ; i<len ; ++i)
        {
            x[i].real/=len;
            x[i].image/=len;
        }
    }
}
int main()
{
	int n,m;
	while (~scanf("%d",&n))
    {
        int mx=0;
        memset(num,0,sizeof(num));
        for (int i=0 ; i<n ; ++i)
        {
            scanf("%d",&K[i]);
            num[K[i]]++;
            mx=max(mx,K[i]);
        }
        scanf("%d",&m);
        for (int i=0 ; i<m ; ++i)
            scanf("%d",&D[i]);
        int len=1;
        mx+=1;
        while (len<mx*2)
            len<<=1;

        for (int i=0 ; i<len ; ++i)
        {
            if (i<mx)
                x[i]=Complex(num[i],0);
            else
                x[i]=Complex(0,0);
        }
        FFT(x,len,1);
        for (int i=0 ; i<len ; ++i)
            x[i]=x[i]*x[i];
        FFT(x,len,-1);
        for (int i=0 ; i<len ; ++i)
            ans[i]=(ll)(x[i].real+0.5);
        for (int i=0 ; i<n ; ++i)
            ans[K[i]]++;
        ll res=0;
        for (int i=0 ; i<m ; ++i)
            if (D[i]<len && ans[D[i]])
                res++;
        printf("%lld\n",res);
    }
	return 0;
}




亚马逊跨境电商选品数据分析:Python爬虫实战指南 本文将带领大家构建一套完整的亚马逊选品数据采集与分析系统,使用最新的Python技术栈,从零开始爬取亚马逊商品数据,并进行深度分析。 阅读详情

相关推荐

weblogic 集群搭建,双机部署,相关问题记录

4.5.集群搭建1 参考网址https://wenku.baidu.com/view/76365129cd1755270722192e453610661ed95aa4.html IP地址 端口 角色 192.168.1.160 9001 AdminServer ...

zl386119974的专栏 1669

6886 - Golf Bot

6886 Golf Bot Do you like golf? I hate it. I hate golf so much that I decided to build the ultimate golf robot, a robot that will never miss a shot. I simply place it over the ball, choose the rig

Pashudeanan的专栏 1098

Stata实战:用双向固定效应模型分析房价,从数据清洗到结果解读(附完整代码)

本文详细介绍了如何使用Stata实现房价数据的双向固定效应模型分析,从数据清洗到结果解读的全流程。通过具体代码示例,帮助读者掌握面板模型的应用技巧,特别适合经济学和金融学研究者进行房价影响因素分析。

weixin_31528001的博客 277

HNU11376:Golf Bot

Problem description Input The first line has one integer: N, the number of different distances the Golf Bot can shoot. Each of the following N lines has one integer, ki, the di

ACM!荣耀之路! 1601

基-2 16点fft的verilog实现

本文是采用输入8位数据,输出8位数据的16点fft实现,旋转因子采用8位rom存储,分为cos和sin2个rom存储;输入数据以及每一级的输出数据采用8位的ram进行存储,分为实部和虚部进行存储。采用顺序输入,那么输出则为倒序。生成rom,可先在matlab中,计算出cos和sin的值,然后写入coe文件,再由ip核生成,具体过程自行百度,懒得百度的话,可以发我的邮箱来获得具体的程序。因为本文采用...

juniorofMFC的博客 9991

UVALive 6886 Golf Bot

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4898 简单FFT模板题 #include #include #include using namespace std; const int maxn = 100005; const do

Occult 880

EEGLAB合辑 | 第一节 往EEGLAB导入数据

1、学习Matlab EEGLAB图形界面建立在强大的Matlab脚本语言之上。要使用EEGLAB构建宏命令和执行自定义和自动化处理的全部功能,就需要能够在Matlab中操纵EEGLAB数据结构。由于时间限制,这个wiki没有提供关于Matlab脚本语言的介绍。相反,用户需要在开始研究之前熟悉Matlab。 2、安装EEGLAB和教程文件 首先下载包含教程数据集的EEGLAB(30MB),附下载地址。 (https://sccn.ucsd.edu/eeglab/downloadtoolbox.php) 解压

nvsirgn的博客 5134

UVALive 6886 Golf Bot (FFT)

题目链接 : 点击打开链接 Do you like golf? I hate it. I hate golf so much that I decided to build the ultimate golf robot, a robot that will never miss a shot. I simply place it over the ball, choose the rig

SSimpLe_Y的博客 950

/home 挂载点无法访问 怎么解决 指令可以进入Home目录 du: 无法访问“*“: 输入/输出错误

本文介绍了Linux系统中XFS文件系统损坏的故障排查与修复方法。当/home挂载点出现I/O错误时,通过dmesg发现XFS日志错误和磁盘I/O报错,判断可能是文件系统逻辑损坏或硬件故障。解决方案包括:1)尝试卸载分区;2)使用xfs_repair工具进行预检查和正式修复;3)在极端情况下使用-L参数强制清空日志;4)若存在硬件故障,建议优先进行数据抢救并更换硬盘。最后强调重要数据应先备份,再考虑系统重建。

专注于计算机研发知识和资讯分享 155

华为OD机试真题 新系统【查找能被整除的最大整数】

华为OD新系统机试真题【查找能被整除的最大整数】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【查找能被整除的最大整数】

qq_45776114的博客 672

【mini故事】——golf

这个图是我对这个故事的理解,哈哈哈!是不是,画的很漂亮。 我就是这么觉得的,一目了然。 下面就来说一说这个图片都说了些啥吧。 There was a beautiful woman named Sophie. Sophie had to play TigerWoods in golf in just one month. Sophie was worried.

张文慧 期待每一天更好的自己 613

NTC热敏电阻选型快速指南

NTC(Negative Temperature Coefficient Thermistor)负温度系数热敏电阻器,是由锰Mn,镍Ni,铜Cu,一氧化碳Co等烧结而成的氧化物。其电阻值随温度的升高而减小,即具有复温度系数,故被称为负温度系数热敏电阻。本文对热敏电阻的应用场景,结构特点和选型参数进行总结。

fydar的博客 1295

UVALive 6886 (LA 6886) Golf Bot FFT

题目大意: 就是现在给出N个数, 然后给出M个数询问这M书中有多少个可以是由这N个数中两个相加(同一个数可选两次)组成或者等于这N个数中的某一个 大致思路: 就是构造多项式相乘就可以了, FFT的最简单的应用了, 将N个数a1, a2,...an对应成多项式, 用x^k的系数是1表示N个数中有值为k的, 否则系数用0表示 然后求这个多项式的平方就可以了 代码如下: Re

Gatevin的专栏 2272

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【FFT】 UVALIVE 6886 Golf Bot

通道:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4898 题意:就是现在给出N个数, 然后给出M个数询问这M书中有多少个可以是由这N个数中两个相加(同一个数可选两次)组成或者等于这N个数中的某一个 ...

329

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

UVALive 6886 Golf Bot(FFT)

关键词:FFT 题意:b数组中有多少个数字可以由a数组中的一个或两个数相加构成?(a数组中的每个数字都各不相同)

acmer的随记 757

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

UVALive 6886 Golf Bot FFT

题意 给你n个数,然后再给你一个数k,问这个数是否就是那n个数中的一个,或者说这个数可以由这n个数中的两个构成(可以是自己*2) 题解: 裸的不行的FFT,直接做就好了。 #include using namespace std; const int N = 1200040; const double pi = acos(-1.0); int len; struct C

Ezereal的博客 598

UVALive_6886_Golf Bot(FFT快速傅里叶变换)

题型:数论 题意:        集合A中取1个数或者2个数,其和变成一个新的集合S。q次查询,每次查询输入一个数,问q个数中有多少个数属于集合S。       集合A元素个数2e5,q 分析: 暴力枚举O(C(n,2)+n),O(n^2)复杂度过高。 FFT统计出现了哪些数,然后直接算结果就ok,复杂度O(nlogn)。 只取1个数只需要O(n)标记一下,S1 =

Light_starlight 975

UVALive - 6886 Golf Bot (FFT)

题意:给N个数a[i],再给M个数,问这M个数中有多少满足:出现在N个数中或能表示成某两个数之和. 分析:FFT求出能够生成的数的系数,给出的M个数若在生成的项中系数不为0,则计数+1 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 4e5 + 10; const ...

weixin_30776863的博客 132

UVALIVE6886 Golf Bot (FFT)

题意:打高尔夫 给你n个距离表示你一次可以把球打远的距离    然后对于m个询问 问能否在两杆内把球打进洞 题解:平方一下就好 注意一下x0的系数为1表示打一杆    才发现数组应该开MAXN * 4 之前写的题数据有点不严谨了 #include <stdio.h> #include <algorithm> #include <iostr...

weixin_38166686的博客 130

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

题目链接: http://acm.hust.edu.cn/vjudge/problem/129724 Golf Bot Time Limit: 15000MS 题意 给你n个数,m个查询,对于每个查询,问能不能用n个数中的一个或两个(同一个数可以取两次)相加凑出来。 题解 多项式乘法,用快速傅里叶变化加速,时间复杂度:O(nlogn)。 #include<map> #include...

weixin_30498921的博客 126

UVALive - 6886 Golf Bot (bitset)

题目链接: \quad UVA-6886 题目大意: \quad 给 nnn 个数 A[1,…,n]A[1,…,n]A[1, \ldots, n],mmm 个数 B[1,…,m]B[1,…,m]B[1, \ldots, m];问在 AAA 中选 111 个或 222 个数,能构成 (指相加) 多少个 BBB 中的数? 数据范围: 1≤n,m≤2e51≤Ai,Bi≤2e51≤n,m...

XzzF1024的博客 505

UVALive - 6886 Golf Bot

题目:给你N个数,再给你M个数,问这M个数中有多少数在这N个数中出现过或可以由这N个数中的某2个数相加(可重复使用) 思路:fft 代码: //#pragma comment(linker, "/STACK:1024000000,1024000000") #include #include #include #include #include #include #include #inclu

ACVevtor的博客 353

UVALive 6835 Space Golf-计算几何

题目意思:是在一段长度为d的区域内有许多已知坐标pi和高度hi的障碍物。你要发射一个球经过若干次反弹(越过障碍物)到达终点。反弹次数有限不能超过b,不能正好落在障碍物上,每次碰撞都是理想碰撞,不消耗能量。问最小的出射速度。 解题思路:因为限制的反弹次数是有限的,所以枚举每一个反弹次数,然后求出每个区间长度len=d/(b+1);对于每个区间暴力枚举每个障碍物,若有障碍物在区间内就跳过,否则就判断

lyc1635566ty的博客 593

UVA12879 UVALive6886 Golf Bot【水题】

Do you like golf? I hate it. I hate golf so much that I decided to build the ultimate golf robot, a robot that will never miss a shot. I simply place it over the ball, choose the right direction and d...

海岛Blog 692

UVALive 6886 Golf Bot 桶排+剪枝

这是一道限时15000ms的题,然后我卡了五发超时和RE。 要注意给的dj<=200000 tho: 刚写时的思路就是将机器人可以打出的距离组合后桶排存起来, 但是各种小优化后发现还是T。 最后看出在将机器人打出的距离组合前先从小到达排序,然后在组合时大于200000时跳出即可。#include <iostream> #include <cstdio> #include <cstring> #

米兰的小科比 348
上一篇: HDU5456 Matches Puzzle Game[数位DP]
下一篇: HDU1402 A * B Problem Plus[FFT]
ControlBear
博客等级 码龄11年 34粉丝 51原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值