湘潭邀请赛的一题,名字叫"超级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(湘潭邀请赛 暴力 思维)的更多相关文章

  1. XTU 1250 Super Fast Fourier Transform

    $2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$H$题 排序,二分. 对$a$数组,$b$数组从小到大进行排序. 统计每一个$a[i]$作为较大值的时候与$b[i]$对答案的贡献.反过来再统计 ...

  2. XTUOJ1250 Super Fast Fourier Transform 暴力

    分析:因为加起来不超过1e6,所以最多有1000+个不同的数 做法:离散化搞就好了 #include <cstdio> #include <iostream> #include ...

  3. 数字图像处理实验(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 ...

  4. 「学习笔记」Fast Fourier Transform

    前言 快速傅里叶变换(\(\text{Fast Fourier Transform,FFT}\) )是一种能在\(O(n \log n)\)的时间内完成多项式乘法的算法,在\(OI\)中的应用很多,是 ...

  5. 【OI向】快速傅里叶变换(Fast Fourier Transform)

    [OI向]快速傅里叶变换(Fast Fourier Transform) FFT的作用 ​ 在学习一项算法之前,我们总该关心这个算法究竟是为了干什么. ​ (以下应用只针对OI) ​ 一句话:求多项式 ...

  6. Fast Fourier Transform

    写在前面的.. 感觉自己是应该学点新东西了.. 所以就挖个大坑,去学FFT了.. FFT是个啥? 挖个大坑,以后再补.. 推荐去看黑书<算法导论>,讲的很详细 例题选讲 1.UOJ #34 ...

  7. 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$ ...

  8. 快速傅里叶变换(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. 讲解 ...

  9. Python FFT (Fast Fourier Transform)

    np.fft.fft import matplotlib.pyplot as plt import plotly.plotly as py import numpy as np # Learn abo ...

随机推荐

  1. Jenkins安装

    直接下载使用Jenkins有两种方式:一种是下载war包安装.另一种是下载.zip进行安装. 一..zip解压安装 1.下载Jenkins:地址http://mirrors.jenkins-ci.or ...

  2. Html中<font>标签的使用

    Html中<font>标签的使用 <!doctype html> <html lang="en"> <head> <meta ...

  3. thinkphp修改和删除数据

    1.在控制器MainController里面写一个方法,调用Nation表中的数据. public function zhuyemian() { $n = D("Nation"); ...

  4. c#日期格式化

    系统格式化  符号   语法 示例(2016-05-09 13:09:55:2350) 格式说明 y DateTime.Now.ToString() 2016/5/9 13:09:55 短日期 长时间 ...

  5. java 多线程 1 线程 进程

    Java多线程(一).多线程的基本概念和使用 2012-09-10 16:06 5108人阅读 评论(0) 收藏 举报  分类: javaSE综合知识点(14)  版权声明:本文为博主原创文章,未经博 ...

  6. Bubble Cup 8 finals H. Bots (575H)

    题意: 简单来说就是生成一棵树,要求根到每个叶子节点上的路径颜色排列不同, 且每条根到叶子的路径恰有n条蓝边和n条红边. 求生成的树的节点个数. 1<=n<=10^6 题解: 简单计数. ...

  7. logback日志写入数据库(mysql)配置

    如题  建议将日志级别设置为ERROR.这样可以避免存储过多的数据到数据中. 1  logback 配置文件(如下) <?xml version="1.0" encoding ...

  8. Android 只开启一个Activity实例

    在一个Activity中,多次调用startActivity()来启动另一个Activity,要想只生成一个Activity实例,方法有两种. 方法一:设置起动模式 一个Activity有四种启动模式 ...

  9. MAC下Homebrew的安装

    1.Homebrew是啥东东? Homebrew的官方网站http://brew.sh/index.html上有这么一句“Homebrew installs the stuffyouneed that ...

  10. EBS 中HOST主机并发请求模板

    #!/bin/sh########################################################################################### ...