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 ...
 
随机推荐
- Nodejs事件引擎libuv源码剖析之:句柄(handle)结构的设计剖析
			
声明:本文为原创博文,转载请注明出处. 句柄(handle)代表一种对持有资源的索引,句柄的叫法在window上较多,在unix/linux等系统上大多称之为描述符,为了抽象不同平台的差异,libuv ...
 - [Android]优化相关
			
尽量减少布局的层次,最多10层,可以通过LinearLayout向RelativeLayout的转变来减少层的数量 使用ListView的时候,getView方法中的对象尽量重用
 - ActiveMQ入门实例
			
1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.5.1-bin.zip,然后双击a ...
 - 【学习笔记】Struts2 应用开发步骤
			
1.在web.xml文件中定义核心Filter来拦截用户请求. <!-- 定义Struts 2的核心Filter --> <filter> <filter-name> ...
 - iOS 浅谈:深.浅拷贝与copy.strong
			
深.浅拷贝 copy mutableCopy NSString NSString *string = @"汉斯哈哈哈"; // 没有产生新对象 NSString *copyStri ...
 - .net 面试基础题
			
Reference Link:http://www.yjbys.com/bbs/326026.html const关键字用来声明编译时常量,readonly用来声明运行时常量 密封类不能同时为抽象类 ...
 - Android五岁了
			
今日(2013-9-24),谷歌开源系统Android迎来了它5岁的生日. 时间过得真快啊!当时的android并不被人看好,而现在的android已经成为了全球最大的智能手机操作系统.而现在的诺基亚 ...
 - centos6 安装mysql报错Requires: libc.so.6(GLIBC_2.14)
			
是应为版本弄混了,不可以把el7的mysql装到el6系统上,重新下载centos6对应的版本的,这里是centos6选择el6版本的 wget http://dev.mysql.com/get/my ...
 - Interleaving String
			
https://leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 is formed by th ...
 - Linux kernel4.4.12 添加make menuconfig 可选项
			
Linux kernel 源码添加可选项 闲来无事,顺便记录一篇在Linux kernel make menuconfig 内添加一个可选项. 说不定将来就要用到这个东西呢. linux kernel ...