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 ...
随机推荐
- hdu 4686 Arc of Dream
思路:构造矩阵 a[i]*b[i]=ax*bx*a[i-1]*b[i-1]+ax*by*a[i-1]+ay*bx*b[i-1]+ay*by 代码如下: #include<iostream> ...
- [转]ubuntu server:开机自动登录
原文链接: Ed29.com http://ed29.com/ubuntu%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%87%AA%E5%8A%A8%E7%99%BB%E5%BD%95 ...
- Project Euler 81:Path sum: two ways 路径和:两个方向
Path sum: two ways In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom ...
- eclipse中clean操作中如何将validating除去
eclipse中去掉js validating方法:1. 删除.project文件中的 <buildSpec></buildSpec>中的:<buildCommand&g ...
- ios开发--高德地图SDK使用简介
高德LBS开放平台将高德最专业的定位.地图.搜索.导航等能力,以API.SDK等形式向广大开发者免费开放.本章节我们来简单学习一下如何使用它的定位及地图SDK. 一.相关框架及环境配置 地图SDK 对 ...
- C++:运算符重载函数之"++"、"--"、"[ ]"、"=="的应用
5.2.5 "++"和"--"的重载 对于前缀方式++ob,可以用运算符函数重载为: ob.operator++() //成员函数重载 或 operator++ ...
- jquery index()方法
搜索匹配的元素,并返回相应元素的索引值,从0开始计数. 如果不给 .index() 方法传递参数,那么返回值就是这个jQuery对象集合中第一个元素相对于其同辈元素的位置. 如果参数是一 ...
- java.lang.NumberFormatException: For input string:"filesId"
做项目时候,页面获取出现了这个问题.找了好久一直以为是我字段或者是数据库字段问题导致引起的. 最后才发现是 struts2中jsp我写错了一个参数,一直导致报错.后来改了就好了. 当大家遇到这个问题的 ...
- Android L 使用ART能提高多少性能?
点击打开链接 刚刚结束的 Google I/O 大会上,Android 下一代操作系统「L」带来不少惊喜.新系统运行更快.更省电. 然而开发者对这个新系统也有颇多疑问,比如新的运行模式 ART 对开发 ...
- MyBatis学习总结(5)——实现关联表查询
一对一关联 提出需求 根据班级id查询班级信息(带老师的信息) 创建表和数据 创建一张教师表和班级表,假设一个老师负责教一个班,那么老师和班级之间的关系就是一对一的关系. create table t ...