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 ...
随机推荐
- 【Linux高频命令专题(9)】ls
ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...
- JAVA XMLConfiguration解决StringXML及多节点
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configurat ...
- stringUtils是apache下的Java jar补充包
org.apache.commons.lang.StringUtils StringUtils中一共有130多个方法,并且都是static的, 所以我们可以这样调用StringUtils.xxx().
- 利用python 获取 windows 组策略
工作中有时候会有这种需求: 1. 自动配置组策略的安全基线,这个东西不用你自己写了,微软有这个工具,Microsoft Security Compliance Manager,你可以在下面的地址去下载 ...
- Sqlmap基础(一)
(1)选项:-r REQUESTFILE Load HTTP request from a file (2)选项:--current-db Retrieve DBMS curr ...
- thrift总结
定义: Apache Thrift是一个facebook建立的RPC框架,现在是一个Apache的顶级项目.Thrift允许通过一个跨语言的定义文件的方式定义数据类型和服务接口,[这个文件]作为[RP ...
- spring-boot-quartz, 依赖spring-boot-parent
spring-boot-quartz, 依赖spring-boot-parent spring-boot Easyui Quartz 项目启动后输入:http://localhost/ 数据库文件: ...
- jQuery 表格排序插件 Tablesorter 使用
jQuery 表格排序插件 Tablesorter 使用方式如下: 1.引入头文件(注意一定要把jQuery放在前面): <script src="lib/jquery-1.8.3.m ...
- js学习对象创建
Object.extend = function(destination, source) {for (var property in source) { destination[propert ...
- [HDOJ4738]Caocao's Bridges(双联通分量,割边,tarjan)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 给一张无向图,每一条边都有权值.找一条割边,使得删掉这条边双连通分量数量增加,求权值最小那条. ...