#1388 : Periodic Signal

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

描述

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.

输入

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.

输出

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

样例输入
2
9
3 0 1 4 1 5 9 2 6
5 3 5 8 9 7 9 3 2
5
1 2 3 4 5
2 3 4 5 1
样例输出
80
0
这题啊,我觉得暴力可做,刚开始超时了,又做了一点优化还是不行啊。
然后我觉得这个k的取值,和排完序的前m项有很大的关系,然后取m在不超时和wa的范围之间。。。这个看运气,竟然AC了
我的思路是排序a, b数组,按住其中一个数组不动,在前m个数内,用a1的下标减去b的下标,取一个得到k的最大值就好
正规做法竟然是fft。。不会啊
我的方法是歪门邪道。。看看就好,不要采纳
 #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i, 1, n)
#define FORP(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i <(n); ++i)
#define SZ(x) ((int)(x).size )
#define ALL(x) (x).begin(), (x.end())
#define MSET(a, x) memset(a, x, sizeof(a))
using namespace std; typedef long long int ll;
typedef pair<int, int> P;
ll read() {
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'') {
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='') {
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
const double pi=.14159265358979323846264338327950288L;
const double eps=1e-;
const int mod = 1e9 + ;
const int INF = 0x3f3f3f3f;
const int MAXN = ;
const int xi[] = {, , , -};
const int yi[] = {, -, , }; int N, T;
ll a[], b[];
ll c[], d[];
struct asort {
int num;
ll date;
} sa[], sb[];
bool cmp(asort a, asort b) {
return a.date > b.date;
}
int main() {
//freopen("in.txt", "r", stdin);
int t, n, k;
scanf("%d", &t); while(t--) {
ll sum = ;
scanf("%d", &n); for(int i = ; i < n; i++) a[i] = read();
for(int i = ; i < n; i++) b[i] = read();
for(int i = n; i < *n ; i++) {
a[i] = a[i-n];
b[i] = b[i-n];
}
for(int i = ; i < n; i++) {
sum += a[i]*a[i];
sum += b[i]*b[i];
sa[i].num = i, sa[i].date = a[i];
sb[i].num = i, sb[i].date = b[i];
}
sort(sa, sa+n, cmp);
sort(sb, sb+n, cmp);
int m = min(n, );
ll res = ;
for(int ai = ; ai < m; ai++) {
ll ans = ;
int i = (sb[].num - sa[ai].num + n)%n;
for(int j = i; j < n+i; j++) {
ans += (a[j-i]*b[j]) <<;
}
if(ans > res) {
res = ans;
k = i;
}
}
printf("%lld\n", sum - res);
// printf("%d\n", k);
}
return ;
}
 

hihocoder 1388 &&2016 ACM/ICPC Asia Regional Beijing Online Periodic Signal的更多相关文章

  1. 2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元

    hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

  2. 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp

    QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  4. 2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp

    odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. 2016 ACM/ICPC Asia Regional Dalian Online 1002/HDU 5869

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  6. 2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  7. HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Friends and Enemies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  8. HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  9. HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

随机推荐

  1. 【转】 StringUtils中 isNotEmpty 和isNotBlank的区别

    [转自]http://blog.csdn.net/foamflower/article/details/5713604 isNotEmpty将空格也作为参数,isNotBlank则排除空格参数 Str ...

  2. 使用PHP搭建书虫网站

    年前开始了一个新项目,书虫项目的启动,项目组里面我是负责搭建网站的.以前听说过PHP的大名,就是没怎么看过,只能从一无所知开始了. 来自PHP手册的介绍:PHP, 即“PHP: Hypertext P ...

  3. 解决Spring MVC @ResponseBody返回html中中文字符串乱码问题

    最近有个应用,通过responsebody返回完整的html页面时出现乱码是异常的问题,因为是通过responsebody返回,所以一开始设置了text/plain的字符集,如下: <mvc:a ...

  4. NYOJ 1058 部分和问题

    部分和问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 给定整数a1.a2........an,判断是否可以从中选出若干数,使它们的和恰好为K.   输入 首先, ...

  5. 实验12:Problem J: 动物爱好者

    #define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...

  6. 文件快速搜索工具-Everything的使用(转)

    首先它是一款基于名称实时定位文件和目录的搜索工具,有以下几个优点: 快速文件索引 快速文件搜索 较低资源占用 轻松分享文件索引 实时跟踪文件更新 通过使用everything小工具,可以提高我们的工作 ...

  7. 转:HTTP 1.1与HTTP 1.0的比较

    原文地址:http://blog.csdn.net/elifefly/article/details/3964766 HTTP 1.1与HTTP 1.0的比较 一个WEB站点每天可能要接收到上百万的用 ...

  8. dom4j创建xml

    在前边介绍SAX,PULL等等既然能解析,当然也能生成.不过这里介绍dom4j创建xml文件,简单易懂. dom4j是独立的api,官网:http://www.dom4j.org/    可以去这下载 ...

  9. 在Eclipse设置打开项目或文件目录

      Run-->External Tools-->Open External Tools Dialog... new 一个 program location 里面填 :C:\WINDOWS ...

  10. 【读书笔记】iOS-内存管理

    Cocoa的内存管理:retain,release和autorelease. 每个对象都维护一个保留计数器.对象被创建时,其保留计数器值为1:对象被保留时,保留计数器值加1:对象被释放时,保留计数器值 ...