hihocoder 1388 &&2016 ACM/ICPC Asia Regional Beijing Online Periodic Signal
#1388 : Periodic Signal
描述
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的更多相关文章
- 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 ...
- 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 ...
- 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) ...
- 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 ...
- 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 ( ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- fibonacci封闭公式
Description 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列 (f[0]=0,f[1]=1;f[i] = f[i-1]+f ...
- 第二章--Win32程序运行原理 (部分概念及代码讲解)
学习<Windows程序设计>记录 概念贴士: 1. 每个进程都有赋予它自己的私有地址空间.当进程内的线程运行时,该线程仅仅能够访问属于它的进程的内存,而属于其他进程的内存被屏蔽了起来,不 ...
- mongodb学习4---索引
1,mongodb的性能分析 db.active.find({id:'sdfasdf6jh67j353g346hkfgh6'}).explain('executionStats') "mil ...
- python3学习笔记目录
目录: Python基础(一),Day1 python基础(二),Day2 python函数和常用模块(一),Day3 python函数和常用模块(二),Day4 python函数和常用模块(三),D ...
- java中使用 正则 抓取邮箱
我们来抓取豆瓣网的邮箱吧!把这个页面的所有邮箱都抓取下来 如https://www.douban.com/group/topic/8845032/: 代码如下: package cn.zhangzon ...
- log4j.xml 配置参数属性level使用心得
jdbc.sqlonly 只显示执行的sql语句.info级才可以显示,debug增加显示java源代码位置. jdbc.sqltiming 显示执行的sql语句以及语句执行时间, ...
- Android sdk manager不能更新下载缓慢的解决方法
通常情况下,下载Android SDK需要连接谷歌的服务器进行下载,由于国内水深火热的网络,速度基本为0.好在国内也有一个更新的镜像地址.本文章介绍如何在不FQ的情况下,使用国内镜像地址,更新andr ...
- Oauth笔记
上周的工作有安全验证这一块,但不懂,只知道有几个关键字Oauth.secret-key .token.签名等.今天就查下资料做笔记. Oauth是什么 不依靠用户账号和密码就能获得访问资源权限 本质: ...
- bootstrap第一天,响应式布局,栅格系统运用
<!DOCTYPE html><html lang="zh-CN"> <head> <meta charset="utf-8&q ...
- 浅谈Base64编码算法
一.什么是编码解码 编码:利用特定的算法,对原始内容进行处理,生成运算后的内容,形成另一种数据的表现形式,可以根据算法,再还原回来,这种操作称之为编码. 解码:利用编码使用的算法的逆运算,对经过编码的 ...