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 ...
随机推荐
- js倒计时防页面刷新
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 泛函编程(20)-泛函库设计-Further Into Parallelism
上两节我们建了一个并行运算组件库,实现了一些基本的并行运算功能.到现在这个阶段,编写并行运算函数已经可以和数学代数解题相近了:我们了解了问题需求,然后从类型匹配入手逐步产生题解.下面我们再多做几个练习 ...
- 【图解】Eclipse下JRebel6.2.0热部署插件安装、破解及配置【转】
标签: 这两天在做后台管理系统,前端框架用Bootstrap,后端用SpringMVC+Velocity.在开发过程中,经常需要对界面进行微调,调整传参等,每次更改一次java代码,就得重新部署一次, ...
- MyEclipse8.6安装SVN 教程 与遇到的问题
按网上的多种方式都不好用 最后这种好用 了! 写此文做记录. MyEclipse版本:8.6 SVN版本:1.6.9 MyEclipse版本要对应SVN版本.否则会出错. 教程: 1.下载最新 ...
- 机器学习实战 - 读书笔记(14) - 利用SVD简化数据
前言 最近在看Peter Harrington写的"机器学习实战",这是我的学习心得,这次是第14章 - 利用SVD简化数据. 这里介绍,机器学习中的降维技术,可简化样品数据. 基 ...
- CSS布局——居中
参考文章1.CSS布局奇淫技巧之--各种居中 2.http://www.imooc.com/article/2235 1.行内元素水平居中text-align:center对图片,按钮,文字等行内元素 ...
- offset笔记
1.offsetParent 2.offsetTop 3.offsetLeft 4.offsetWidth 5.offsetHeight offsetWidth是元素的可视宽度,这个宽度包括元素的边框 ...
- andriod 用户名和密码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- LayoutTransition实现显示、隐藏动画
public class Main4Activity extends Activity { private TextView tv1; private Button button1; private ...
- iOS 基础日记-修饰符
今晚随便温习了一下iOS 基础关于修饰符这块的东西,下面简单的来描述一下,其中有的也是在网络学习到的: strong与weak是由ARC新引入的对象变量属性 ARC的解释:ARC引入了新的对象的生命周 ...