XTU 1250 Super Fast Fourier Transform
$2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$H$题
排序,二分。
对$a$数组,$b$数组从小到大进行排序。
统计每一个$a[i]$作为较大值的时候与$b[i]$对答案的贡献。反过来再统计以$b[i]$为较大值时与$a[i]$对答案的贡献。
以前者举例说明:
观察这个:$⌊\sqrt {|a[i] - b[j]|}⌋ $,按照题目中给出的范围,这个东西最大只有$1000$。
也就是说,我们在计算一个$a[i]$与$b[j]$对答案的贡献时候,不用从$1$到$m$枚举$j$,因为肯定是一段一段相同的,所以分段计算即可。二分一下就可以分段计算了。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-; const int maxn=;
int n,m;
int a[maxn],b[maxn]; int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++) scanf("%d",&b[i]);
sort(a+,a++n); sort(b+,b++m); LL ans=;
for(int i=;i<=n;i++)
{
int L=,R=m,pos=-;
while(L<=R)
{
int mid=(L+R)/;
if(b[mid]<a[i]) L=mid+,pos=mid;
else R=mid-;
}
if(pos==-) continue; int now=, p;
while(now<=pos)
{
int num=(int)(eps+sqrt(1.0*(a[i]-b[now])));
L=now,R=pos;
while(L<=R)
{
int mid=(L+R)/;
int tmp=(int)(eps+sqrt(1.0*(a[i]-b[mid])));
if(tmp<num) R=mid-;
else L=mid+,p=mid;
}
ans=ans+(LL)(p-now+)*(LL)num;
now=p+;
}
} for(int i=;i<=m;i++)
{
int L=,R=n,pos=-;
while(L<=R)
{
int mid=(L+R)/;
if(a[mid]<b[i]) L=mid+,pos=mid;
else R=mid-;
}
if(pos==-) continue; int now=, p;
while(now<=pos)
{
int num=(int)(eps+sqrt(1.0*(b[i]-a[now])));
L=now,R=pos;
while(L<=R)
{
int mid=(L+R)/;
int tmp=(int)(eps+sqrt(1.0*(b[i]-a[mid])));
if(tmp<num) R=mid-;
else L=mid+,p=mid;
}
ans=ans+(LL)(p-now+)*(LL)num;
now=p+;
}
}
cout<<ans<<endl;
}
return ;
}
XTU 1250 Super Fast Fourier Transform的更多相关文章
- 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)
湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...
- XTUOJ1250 Super Fast Fourier Transform 暴力
分析:因为加起来不超过1e6,所以最多有1000+个不同的数 做法:离散化搞就好了 #include <cstdio> #include <iostream> #include ...
- 数字图像处理实验(5):PROJECT 04-01 [Multiple Uses],Two-Dimensional Fast Fourier Transform 标签: 图像处理MATLAB数字图像处理
实验要求: Objective: To further understand the well-known algorithm Fast Fourier Transform (FFT) and ver ...
- 「学习笔记」Fast Fourier Transform
前言 快速傅里叶变换(\(\text{Fast Fourier Transform,FFT}\) )是一种能在\(O(n \log n)\)的时间内完成多项式乘法的算法,在\(OI\)中的应用很多,是 ...
- 【OI向】快速傅里叶变换(Fast Fourier Transform)
[OI向]快速傅里叶变换(Fast Fourier Transform) FFT的作用 在学习一项算法之前,我们总该关心这个算法究竟是为了干什么. (以下应用只针对OI) 一句话:求多项式 ...
- Fast Fourier Transform
写在前面的.. 感觉自己是应该学点新东西了.. 所以就挖个大坑,去学FFT了.. FFT是个啥? 挖个大坑,以后再补.. 推荐去看黑书<算法导论>,讲的很详细 例题选讲 1.UOJ #34 ...
- Fast Fourier Transform ——快速傅里叶变换
问题: 已知$A=a_{0..n-1}$, $B=b_{0..n-1}$, 求$C=c_{0..2n-2}$,使: $$c_i = \sum_{j=0}^ia_jb_{i-j}$$ 定义$C$是$A$ ...
- 快速傅里叶变换(Fast Fourier Transform, FFT)和短时傅里叶变换(short-time Fourier transform,STFT )【资料整理】【自用】
1. 官方形象展示FFT:https://www.bilibili.com/video/av19141078/?spm_id_from=333.788.b_636f6d6d656e74.6 2. 讲解 ...
- Python FFT (Fast Fourier Transform)
np.fft.fft import matplotlib.pyplot as plt import plotly.plotly as py import numpy as np # Learn abo ...
随机推荐
- 【xcode插件介绍】Alcatraz ----The package manager for Xcode
对于许多iOS开发者而言,Alcatraz并不陌生,甚至是相当的喜闻乐见.Alcatraz是一款开源的Xcode包管理器,由Marin Usalj.Delisa Mason和Jurre Stender ...
- ETHREAD APC
ETHREAD APC <寒江独钓>内核学习笔记(4) 继续学习windows 中和线程有关系的数据结构: ETHREAD.KTHREAD.TEB 1. 相关阅读材料 <window ...
- LigerUI+MVC的应用1
[项目开发]LigerUI+MVC的应用(一) 近期因为稍微空闲有点时间,就晚上回家自己在随便写写代码,也就边写边记,中间主要采用了微软的MVC4.0框架.虽然目前公司也是使用的MVC的模式,但是因为 ...
- python读写protobuf
0. 前期准备 官方protobuf定义 https://code.google.com/p/protobuf/ python使用指南 https://developers.google. ...
- jQuery实现返回顶部功能
整理两个实现功能,一个是右下角的返回顶部,一个是右侧的返回顶部,分别如图 第一种实现 一.JSP或HTML(主体结构) 在body中添加 <body id=" ...
- HTML + Javascript开发AIR应用
HTML + Javascript开发AIR应用 目录 背景什么是AIR?环境准备运行效果开发过程目录结构应用程序描述符HTML页面调试备注 背景返回目录 断断续续用Winform和WPF开发过一些小 ...
- 我的Emacs折腾经验谈(四) 也谈Yasnippet
又是好久没更新了,不过还好,现在慢慢有点感觉了,好长时间不写博客会心里有点感觉欠一点什么东西.觉得每次写了东西都往主页推搞得压力好大,以后就不往网站首页推了,纯留下来供参考,另外就是主要方便从搜索找过 ...
- 编写类String 的构造函数、析构函数和赋值函数
编写类String 的构造函数.析构函数和赋值函数,已知类String 的原型为:class String{public:String(const char *str = NULL); // 普通构造 ...
- UVA 216 - Getting in Line
216 - Getting in Line Computer networking requires that the computers in the network be linked. This ...
- Android 短信模块分析(二) MMS中四大组件核心功能详解
接下来的分析先从MMS中四大组件(Activity ,BroadCastReceiver,Service,ContentProvider),也是MMS中最核心的部分入手: 一. Activity 1 ...