博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hihocoder 1388 Periodic Signal
阅读量:5104 次
发布时间:2019-06-13

本文共 2581 字,大约阅读时间需要 8 分钟。

Periodic Signal
 
时间限制:5000ms
单点时限:5000ms
内存限制:256MB

Description

Profess X is an expert in signal processing. He has a device which can send a particular 1 second signal repeatedly. The signal is A0 ... An-1 under n Hz sampling.

One day, the device fell on the ground accidentally. Profess X wanted to check whether the device can still work properly. So he ran another n Hz sampling to the fallen device and got B0 ... Bn-1.

To compare two periodic signals, Profess X define the DIFFERENCE of signal A and B as follow:

You may assume that two signals are the same if their DIFFERENCE is small enough. 
Profess X is too busy to calculate this value. So the calculation is on you.

Input

The first line contains a single integer T, indicating the number of test cases.

In each test case, the first line contains an integer n. The second line contains n integers, A0 ... An-1. The third line contains n integers, B0 ... Bn-1.

T≤40 including several small test cases and no more than 4 large test cases.

For small test cases, 0<n≤6⋅103.

For large test cases, 0<n≤6⋅104.

For all test cases, 0≤Ai,Bi<220.

Output

For each test case, print the answer in a single line.

Sample Input
293 0 1 4 1 5 9 2 65 3 5 8 9 7 9 3 251 2 3 4 52 3 4 5 1
Sample Output
800
/* * hihocoder 1388 Periodic Signal * * 把式子变形一下就是求Ai*Bi+k求和的最大值,想到用FFT来求 * 会因为精度问题不能过,这是找出最小的那个k,然后重新算即可。 */#include 
using namespace std;const int MAXN = 200000+10;const double PI = acos(-1.0);struct Complex{ double r,i; Complex(double _r=0,double _i=0):r(_r),i(_i){} Complex operator + (const Complex& rhs) { return Complex(r+rhs.r,i+rhs.i); } Complex operator - (const Complex& rhs) { return Complex(r-rhs.r,i-rhs.i); } Complex operator * (const Complex &rhs) { return Complex(r*rhs.r - i*rhs.i,i*rhs.r + r*rhs.i); }};/* * 进行FFT和IFFT前的反转变换。 * 位置i和 (i二进制反转后位置)互换 * len必须取2的幂 */void Rader(Complex F[],int len){ int j = len >> 1; for(int i = 1;i < len - 1;++i) { if(i < j) swap(F[i],F[j]); // reverse int k = len>>1; while(j>=k) { j -= k; k >>= 1; } if(j < k) j += k; }}/* * 做FFT * len必须为2^k形式, * on==1时是DFT,on==-1时是IDFT */void FFT(Complex F[],int len,int t){ Rader(F,len); for(int h=2;h<=len;h<<=1) { Complex wn(cos(-t*2*PI/h),sin(-t*2*PI/h)); for(int j=0;j
ans) { ans=va[i].r; k=i; } } k-=n-1; long long a=0,b=0,ab=0; for(int i=0;i

 

转载于:https://www.cnblogs.com/wangdongkai/p/5906954.html

你可能感兴趣的文章
GDOI DAY1游记
查看>>
收集WebDriver的执行命令和参数信息
查看>>
数据结构与算法(三)-线性表之静态链表
查看>>
mac下的mysql报错:ERROR 1045(28000)和ERROR 2002 (HY000)的解决办法
查看>>
快速幂
查看>>
AIO 开始不定时的抛异常: java.io.IOException: 指定的网络名不再可用
查看>>
MyBaits动态sql语句
查看>>
HDU4405(期望DP)
查看>>
拉格朗日乘子法 那些年学过的高数
查看>>
vs code 的便捷使用
查看>>
Spring MVC @ResponseBody返回中文字符串乱码问题
查看>>
用户空间与内核空间,进程上下文与中断上下文[总结]
查看>>
JS 中的跨域请求
查看>>
JAVA开发环境搭建
查看>>
mysql基础语句
查看>>
Oracle中的rownum不能使用大于>的问题
查看>>
[Data Structure & Algorithm] 有向无环图的拓扑排序及关键路径
查看>>
cassandra vs mongo (1)存储引擎
查看>>
Visual Studio基于CMake配置opencv1.0.0、opencv2.2
查看>>
遍历Map对象
查看>>