1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)
湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训。
由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可。
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
const int N = 1000008, INF = 0x3F3F3F3F;
int sq[N];
int a[N], b[N];
struct data{
int num, cnt;
}a1[N], b1[N];
int t1, t2; int main(){
for(int i = 0; i < N; i++){
sq[i] = sqrt(i + 0.01);
}
int n, m;
while(~scanf("%d %d", &n, &m)){
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int mx = 0;
int tp;
for(int i = 0; i < n; i++){
scanf("%d", &tp);
mx = max(mx, tp);
a[tp]++;
} for(int i = 0; i < m; i++){
scanf("%d", &tp);
mx = max(mx, tp);
b[tp]++;
} t1 = t2 = 0;
for(int i = 0; i <= mx; i++){
if(a[i]){
a1[t1].num = i;
a1[t1].cnt = a[i];
t1++;
}
if(b[i]){
b1[t2].num = i;
b1[t2].cnt = b[i];
t2++;
}
}
LL ans = 0;
for(int i = 0; i < t1; i++){
for(int j = 0; j < t2; j++){
ans += (LL)a1[i].cnt * (LL)b1[j].cnt * sq[abs(a1[i].num - b1[j].num)];
}
}
cout<<ans<<"\n"; } return 0;
}
1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)的更多相关文章
- XTU 1250 Super Fast Fourier Transform
$2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$H$题 排序,二分. 对$a$数组,$b$数组从小到大进行排序. 统计每一个$a[i]$作为较大值的时候与$b[i]$对答案的贡献.反过来再统计 ...
- 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 ...
随机推荐
- Android开发环境搭建
导读: 学习Android开发第一步就是搭建Android开发环境. 1.安装JDK JDK(Java SE Development Kit)是Java的开发工具集.SE表示标准版. JRE(Java ...
- Windows快捷键
一.常见用法: F1 显示当前程序或者windows的帮助内容. F2 当你选中一个文件的话,这意味着“重命名” F3 当你在桌面上的时候是打开“查找:所有文件” 对话框 F10或ALT 激活当前程序 ...
- mysql获取一个表中的下一个自增(id)值的方法
SELECT Auto_increment FROM information_schema.`TABLES` WHERE Table_Schema='数据库名' AND table_name = '表 ...
- 【jQuery】选择器
jQ提供了很多选择器:(注:$("p").action() action为后续动作) 元素选择器 $("p").action() ; //选取所有p标签 id选 ...
- Linux C 收藏
某招聘要求:熟悉高性能分布式网络服务端设计开发,熟悉epoll.多线程.异步IO.事件驱动等服务端技术: <UNIX环境高级编程(第3版)>apue.h等源码文件的编译安装 <UNI ...
- jQuery stop()用法
jQuery stop()的用法: stop(true)等价于stop(true,false): 停止被选元素的所有加入队列的动画. stop(true,true):停止被选元素的所有加入队列的动画, ...
- Json.net日期格式化
1. 全局设置,可以在App_Global中配置 JsonSerializerSettings setting = new JsonSerializerSettings(); JsonConvert. ...
- MetInfo 5.1 自动化getshell工具
title: MetInfo V5.1 GetShell一键化工具 date: 2016-06-08 22:40:32 categories: Hacker tags: - Hacker - Tool ...
- C# 调用webservice 几种办法(转载)
原文地址: http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html //=========================== ...
- Euler Tour Tree与dynamic connectivity
Euler Tour Tree最大的优点就是可以方便的维护子树信息,这点LCT是做不到的.为什么要维护子树信息呢..?我们可以用来做fully dynamic connectivity(online) ...