hihocoder1388 Periodic Signal
FFT 就可以了 比赛时候没时间做了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 6e4+5;
int A[MAXN<<2], B[MAXN<<2], C[MAXN<<2];
struct FFTSOLVE {
int pos[MAXN<<2];
struct comp {
double r , i ;
comp ( double _r = 0 , double _i = 0 ) : r ( _r ) , i ( _i ) {}
comp operator + ( const comp& x ) {
return comp ( r + x.r , i + x.i ) ;
}
comp operator - ( const comp& x ) {
return comp ( r - x.r , i - x.i ) ;
}
comp operator * ( const comp& x ) {
return comp ( r * x.r - i * x.i , i * x.r + r * x.i ) ;
}
comp conj () {
return comp ( r , -i ) ;
}
} A[MAXN<<2] , B[MAXN<<2] ;
const double pi = acos ( -1.0 ) ;
void FFT ( comp a[] , int n , int t ) {
for ( int i = 1 ; i < n ; ++ i ) if ( pos[i] > i ) swap ( a[i] , a[pos[i]] ) ;
for ( int d = 0 ; ( 1 << d ) < n ; ++ d ) {
int m = 1 << d , m2 = m << 1 ;
double o = pi * 2 / m2 * t ;
comp _w ( cos ( o ) , sin ( o ) ) ;
for ( int i = 0 ; i < n ; i += m2 ) {
comp w ( 1 , 0 ) ;
for ( int j = 0 ; j < m ; ++ j ) {
comp& A = a[i + j + m] , &B = a[i + j] , t = w * A ;
A = B - t ;
B = B + t ;
w = w * _w ;
}
}
}
if ( t == -1 ) for ( int i = 0 ; i < n ; ++ i ) a[i].r /= n ;
}
void mul ( int *a , int *b , int *c ,int k) {
int i , j ;
for ( i = 0 ; i < k ; ++ i ) A[i] = comp ( a[i] , b[i] ) ;
j = __builtin_ctz ( k ) - 1 ;
for ( int i = 0 ; i < k ; ++ i ) {
pos[i] = pos[i >> 1] >> 1 | ( ( i & 1 ) << j ) ;
}
FFT ( A , k , 1 ) ;
for ( int i = 0 ; i < k ; ++ i ) {
j = ( k - i ) & ( k - 1 ) ;
B[i] = ( A[i] * A[i] - ( A[j] * A[j] ).conj () ) * comp ( 0 , -0.25 ) ;
}
FFT ( B , k , -1 ) ;
for ( int i = 0 ; i < k ; ++ i ) {
c[i] = ( long long ) ( B[i].r + 0.5 );
}
}
}boy;
int N;
int s1[MAXN], s2[MAXN];
int main(){
int T; scanf("%d",&T);
while(T--) {
ll ans = 0;
memset(A,0,sizeof(A));
memset(B,0,sizeof(B));
scanf("%d",&N);
for(int i = 0; i < N; ++i) {
scanf("%d",&s1[i]);
}
for(int i = 0; i < N; ++i) {
scanf("%d",&s2[i]);
}
int len = 1; while(len < N*2) len <<= 1;
for(int i = 0; i < N; ++i) {
A[i] = s1[N-i-1]; B[i] = s2[i];
}
for(int i = N; i < 2*N; ++i) {
A[i] = 0; B[i] = s2[i-N];
}
boy.mul(A,B,C,len);
double an = -1; double eps = 1e-8; int pos;
for(int i = 0; i < N; ++i) {
if(an+eps < boy.B[i+N-1].r) {
an = boy.B[i+N-1].r; pos = i;
}
}
for(int i = 0; i < N; ++i) {
ans += 1ll*(s1[i]-s2[(i+pos)%N]) * (s1[i]-s2[(i+pos)%N]);
}
printf("%lld\n",ans);
}
return 0;
}
hihocoder1388 Periodic Signal的更多相关文章
- hihoCoder1388 Periodic Signal(2016北京网赛F:NTT)
题目 Source http://hihocoder.com/problemset/problem/1388 Description Profess X is an expert in signal ...
- hihocoder #1388 : Periodic Signal NTT&FFT
传送门:hihocoder #1388 : Periodic Signal 先来几个大牛传送门: (模板) NTT long long 版 解法一:因为我们知道FFT会精度不够,所以坚持用NTT,但 ...
- hihocoder 1388 &&2016 ACM/ICPC Asia Regional Beijing Online Periodic Signal
#1388 : Periodic Signal 时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal proce ...
- hihocoder #1388 : Periodic Signal fft
题目链接: https://hihocoder.com/problemset/problem/1388 Periodic Signal 时间限制:5000ms内存限制:256MB 问题描述 Profe ...
- hihocode #1388 : Periodic Signal NTT
#1388 : Periodic Signal 描述 Profess X is an expert in signal processing. He has a device which can ...
- hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)
时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device w ...
- 【hihocoder#1388】Periodic Signal NTT
题目链接:http://hihocoder.com/problemset/problem/1388?sid=974337 题目大意:找出一个$k$,使得$\sum_{i=0}^{n-1}(A_{i}- ...
- hihoCoder 1388 Periodic Signal(FFT)
[题目链接] http://hihocoder.com/problemset/problem/1388 [题目大意] 给出A数列和B数列,求下图式子: [题解] 我们将多项式拆开,我们可以得到固定项A ...
- hihoCoder #1388 : Periodic Signal
NTT (long long 版) #include <algorithm> #include <cstring> #include <string.h> #inc ...
随机推荐
- BZOJ 1758: [Wc2010]重建计划 [暂时放弃]
今天晚上思维比较乱,以后再写写吧#include <iostream> #include <cstdio> #include <cstring> #include ...
- 除了使用URLSearchParams处理axios发送的数据,但是兼容性不好,其他的兼容方法
在使用axios这个ajax插件的时候,我们有些时候会遇到一些问题,比如:数据格式不正确 以最简单的例子为基础(这里使用post方法): 在上面的例子中我们直接调用axios的post方法,传给后台的 ...
- .net使用AsposeWord导出word table表格
本文为原创,转载请注明出处 1.前言 .net平台下导出word文件还可以使用Microsoft.Office.Interop和NPOI,但是这两者都有缺点,微软的Office.Interop组件需要 ...
- vue调试工具之 vue-devtools的安装
这里介绍一下vue-devtools的安装方法之一: chrome浏览器的应用商店不能直接访问(需要跨域),所以直接应用商店安装的方法就行不通了. 1.到github主页去下载安装: git clon ...
- LNMP搭建02 -- 编译安装Nginx
[编译安装Nginx] 为了顺利安装Nginx,先安装下面这些: [CentOS 编译 nginx 前要做的事情] yum install gcc gcc-c++ kernel-devel yum ...
- Navi.Soft31.产品.微信聊天(永久免费)
1系统简介 1.1功能简述 微信确实是一款优秀的社交的软件,被越来越多的人使用.它的电脑版最新版本是2.6,更新也比较及时,只是它有一个功能差强人意,就是同一台电脑只能运行一个微信号,不知道为何这样设 ...
- Jupyter 初体验
简介 Jupyter notebook 是一个非常强大的工具,可以创建漂亮的交互式文档. 安装 安装环境:win7专业版32位系统 + python 3.6.4 安装命令:pip install ju ...
- AC Dream1069
这题的加密字符 - (Fibnacci % 26),如果得到的字符小于'a',就等于加密字符 - (Fibnacci % 26)+26. 获得题目的函数如下: void getItem(){ char ...
- APP性能测试(CPU)
获取数据 :adb shell dumpsys cpuinfo | grep packagename result = os.popen("adb shell dumpsys cpuinfo ...
- 一个逼格很低的appium自动化测试框架
Github地址: https://github.com/wuranxu 使用说明 1. 安装配置Mongo数据库 下载地址 mongo是用来存放元素定位的,截图如下: 通过case_id区分每个ca ...