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的更多相关文章

  1. hihoCoder1388 Periodic Signal(2016北京网赛F:NTT)

    题目 Source http://hihocoder.com/problemset/problem/1388 Description Profess X is an expert in signal ...

  2. hihocoder #1388 : Periodic Signal NTT&FFT

    传送门:hihocoder #1388 : Periodic Signal 先来几个大牛传送门:  (模板) NTT long long 版 解法一:因为我们知道FFT会精度不够,所以坚持用NTT,但 ...

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

  4. hihocoder #1388 : Periodic Signal fft

    题目链接: https://hihocoder.com/problemset/problem/1388 Periodic Signal 时间限制:5000ms内存限制:256MB 问题描述 Profe ...

  5. hihocode #1388 : Periodic Signal NTT

    #1388 : Periodic Signal   描述 Profess X is an expert in signal processing. He has a device which can ...

  6. hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)

    时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device w ...

  7. 【hihocoder#1388】Periodic Signal NTT

    题目链接:http://hihocoder.com/problemset/problem/1388?sid=974337 题目大意:找出一个$k$,使得$\sum_{i=0}^{n-1}(A_{i}- ...

  8. hihoCoder 1388 Periodic Signal(FFT)

    [题目链接] http://hihocoder.com/problemset/problem/1388 [题目大意] 给出A数列和B数列,求下图式子: [题解] 我们将多项式拆开,我们可以得到固定项A ...

  9. hihoCoder #1388 : Periodic Signal

    NTT (long long 版) #include <algorithm> #include <cstring> #include <string.h> #inc ...

随机推荐

  1. HDU 2296 Ring [AC自动机 DP 打印方案]

    Ring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...

  2. SDN第四次作业

    作业链接 1.阅读 了解SDN控制器的发展 http://www.sdnlab.com/13306.html http://www.docin.com/p-1536626509.html 了解ryu控 ...

  3. 针对Eclipse的maven Missing artifact com.microsoft.sqlserver:slqjdbc4:jar:4.0

    maven 中添加sqlserver 出错,报错内容 maven Missing artifact com.microsoft.sqlserver 解决方法这里先下载好jar包 ,然后maven命令执 ...

  4. 洛谷 P2194 HXY烧情侣【Tarjan缩点】 分析+题解代码

    洛谷 P2194 HXY烧情侣[Tarjan缩点] 分析+题解代码 题目描述: 众所周知,HXY已经加入了FFF团.现在她要开始喜(sang)闻(xin)乐(bing)见(kuang)地烧情侣了.这里 ...

  5. kubernetes 集群的安装部署

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: 首先kubernetes得官方文档我自己看着很乱,信息很少, ...

  6. Shiro 核心功能案例讲解 基于SpringBoot 有源码

    Shiro 核心功能案例讲解 基于SpringBoot 有源码 从实战中学习Shiro的用法.本章使用SpringBoot快速搭建项目.整合SiteMesh框架布局页面.整合Shiro框架实现用身份认 ...

  7. node.js简单搭建服务,访问本地站点文件

    1.安装nodejs服务(从官网下载安装),node相当于apache服务器 2.在自己定义的目录下新建服务器文件如 server.js 例如,我在D:\nodeJs下创建了server.js文件 v ...

  8. Spring context:property-placeholder 一些坑

    今天在配置多配置文件的时候偶然发现如果我使用   <context:property-placeholder location="classpath:filePath.properti ...

  9. maven使用jstl表达式和The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application解决

    maven 中使用jstl表达式中出现如上错误.原因: 1.由于在maven中的web项目没有自动依赖jstl的jar 未在pom文件中添加jstl相关的jar <!--jstl表达式--> ...

  10. the c programing language 学习过程7

    interact 互动 carriage运费运输 linefeed 换行 redirection改方向 interleaved交叉存取 adequate足够的 untouched原样的  specif ...