XTUOJ1250 Super Fast Fourier Transform 暴力
分析:因为加起来不超过1e6,所以最多有1000+个不同的数
做法:离散化搞就好了
#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e5+;
const int INF=0x3f3f3f3f;
const int mod=1e9+;
int a[N],b[N],c[N],k1[N],k2[N];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i=;i<=n;++i){
scanf("%d",&a[i]);
c[i]=a[i];
}
sort(a+,a++n);
int cnt1=unique(a+,a++n)-a-;
memset(k1,,sizeof(k1));
for(int i=;i<=n;++i){
++k1[lower_bound(a+,a++cnt1,c[i])-a];
}
for(int i=;i<=m;++i){
scanf("%d",&b[i]);
c[i]=b[i];
}
sort(b+,b++m);
int cnt2=unique(b+,b++m)-b-;
memset(k2,,sizeof(k2));
for(int i=;i<=m;++i){
++k2[lower_bound(b+,b++cnt2,c[i])-b];
}
LL ret=;
for(int i=;i<=cnt1;++i){
for(int j=;j<=cnt2;++j){
LL tmp=sqrt(abs(a[i]-b[j]));
ret+=1ll*k1[i]*k2[j]*tmp;
}
}
printf("%I64d\n",ret);
}
return ;
}
XTUOJ1250 Super Fast Fourier Transform 暴力的更多相关文章
- 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)
湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...
- XTU 1250 Super Fast Fourier Transform
$2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$H$题 排序,二分. 对$a$数组,$b$数组从小到大进行排序. 统计每一个$a[i]$作为较大值的时候与$b[i]$对答案的贡献.反过来再统计 ...
- 数字图像处理实验(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 ...
随机推荐
- Android 解决ListView中每一项与button冲突
在listView的item里面如果有button,ImageButton等控件,会使得ListView不会被点击,解决方法是: ①在Button上面添加属性 android:focusable=&q ...
- Project Euler 83:Path sum: four ways 路径和:4个方向
Path sum: four ways NOTE: This problem is a significantly more challenging version of Problem 81. In ...
- MVVM 代码记录
一.XML <Page x:Class="MVVM.MainPage" xmlns="http://schemas.microsoft.com/winfx/20 ...
- Jdk命令之jps
jps -- Java Virtual Machine Process Status Tool jps命令类似于Linux下的ps命令,可以列出本机所有正在运行的java进程.
- 63. Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- linux 查看某一端口的占用情况
查看某一端口的占用情况: lsof -i:端口号,例如查看端口21是否被占用 lsof -i: 实例:查看端口是否被占用,如果被占用结束掉该端口 [root@localhost splunk]# ls ...
- jsp获取struts2查询到的数据
1.在struts2的方法中利用查询语句查询到结果,然后再对结果进行封装,jsp根据封装获取相关信息 struts2的查询和封装方法: private List<FreeMarkerDetail ...
- 点(Dot)与像素(Pixel)的区别
DPI中的点(Dot)与图像分辨率中的像素(Pixel)是容易混淆的两个概念, DPI中的点可以说是硬件设备最小的显示单元, 而像素则既可是一个点,又可是多个点的集合.在扫描仪扫描图像时,扫描仪的每一 ...
- BZOJ 1898 Swamp 沼泽鳄鱼(矩阵)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1898 题意:一个无向图.给出起点和终点,以及某些时刻某些点不能到达的信息.问从起点出发在 ...
- Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.解决办法
刚刚更新AS到2.0版本,然后导入Api Demos的时候出现了这个错误. 解决办法:在AS的菜单栏,Tools->Android ->Enable ADB integration 勾选就 ...