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
- 2
- 样例输出
-
- 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 ;
- }
- 80
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 ...
随机推荐
- 两种设计模式(1)==>>“简单工厂”
我们以做一个计算器为例,给大家介绍简单工厂的应用: 效果: 这里我们使用 继承 ,虚方法, 简单工厂的设计模式来完成 首先,我们除了搭好窗体外,我们应该把我们的一些类准备好: 1.计算的父类Calcu ...
- cas与NGINX整合(转)
CAS (5) -- Nginx代理模式下浏览器访问CAS服务器配置详解 标签: 服务器 2015-12-18 15:04 1633人阅读 评论(0) 收藏 举报 分类: 网络(61) 目录( ...
- Angularjs,WebAPI 搭建一个简易权限管理系统 —— WebAPI项目主体结构(四)
目录 前言 Angularjs名词与概念 Angularjs 基本功能演示 系统业务与实现 WebAPI项目主体结构 Angularjs 前端主体结构 5.0 WebAPI项目主体结构 5.1 总体结 ...
- dbcp/c3p0连接池设置mysql会话变量
我们有几个计算风控值的定时任务,几乎每隔5秒会更新所有账户的当前总资产并以此通知风控,每隔一小时就产生一两个G的binlog,几十台服务器折腾..数据库是公用的,代码是通过工具自动生成的,直接修改流程 ...
- play framework学习笔记之 模板引擎
模板语法 ${client.name} ${client?.name} 不能确定client是否存在的时候? #{extends /} #{doLayout /}#{get} #{set} 比如 #{ ...
- django使用笔记
django的具体使用可以看官方手册http://djangobook.py3k.cn,这里主要记录使用django中遇到的问题. 1.中文编码问题. 因为我们用到的东西基本上都有中文,在settin ...
- Vue基础理论
一 vue的定位 (1)Vue.js是一个构建数据驱动的 web 界面的库. (2)Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件. (3)Vue.js 自身不是一 ...
- 人人都应该学习Markdown
Markdown是一门新兴的标记语言,已经有12年历史了.随着它在全球范围内的流行,很多人已经听说.熟识或者开始使用了. 首先,Markdown既不是工具,也不是程序语言,而是一种十分轻量级的标记语言 ...
- Oracle学习之简单查询
使用scott用户下的表, 1.查询所有内容SELECT * FROM emp; 2.查询员工信息,包括员工编号,姓名,职位3个信息SELECT empno,ename,job FROM emp; 3 ...
- Xcode注释插件 VVDocumenter 升级Xcode6.x 失效的解决办法
失效的原因其实是因为在插件的uuid列表中缺少自己的uuid,解决办法如下; 1,打开终端 输入命令: defaults read /Applications/Xcode.app/Contents/I ...