#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.

样例输入
  1. 2
  2. 9
  3. 3 0 1 4 1 5 9 2 6
  4. 5 3 5 8 9 7 9 3 2
  5. 5
  6. 1 2 3 4 5
  7. 2 3 4 5 1
样例输出
  1. 80
  2. 0
    这题啊,我觉得暴力可做,刚开始超时了,又做了一点优化还是不行啊。
    然后我觉得这个k的取值,和排完序的前m项有很大的关系,然后取m在不超时和wa的范围之间。。。这个看运气,竟然AC
    我的思路是排序a b数组,按住其中一个数组不动,在前m个数内,用a1的下标减去b的下标,取一个得到k的最大值就好
    正规做法竟然是fft。。不会啊
    我的方法是歪门邪道。。看看就好,不要采纳
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. #include <deque>
  7. #include <queue>
  8. #include <stack>
  9. #include <set>
  10. #include <map>
  11. #include <algorithm>
  12. #include <functional>
  13. #include <utility>
  14. #include <bitset>
  15. #include <cmath>
  16. #include <cstdlib>
  17. #include <ctime>
  18. #include <cstdio>
  19. #include <cstring>
  20. #define FOR(i, a, b) for(int i = (a); i <= (b); i++)
  21. #define RE(i, n) FOR(i, 1, n)
  22. #define FORP(i, a, b) for(int i = (a); i >= (b); i--)
  23. #define REP(i, n) for(int i = 0; i <(n); ++i)
  24. #define SZ(x) ((int)(x).size )
  25. #define ALL(x) (x).begin(), (x.end())
  26. #define MSET(a, x) memset(a, x, sizeof(a))
  27. using namespace std;
  28.  
  29. typedef long long int ll;
  30. typedef pair<int, int> P;
  31. ll read() {
  32. ll x=,f=;
  33. char ch=getchar();
  34. while(ch<''||ch>'') {
  35. if(ch=='-')f=-;
  36. ch=getchar();
  37. }
  38. while(ch>=''&&ch<='') {
  39. x=x*+ch-'';
  40. ch=getchar();
  41. }
  42. return x*f;
  43. }
  44. const double pi=.14159265358979323846264338327950288L;
  45. const double eps=1e-;
  46. const int mod = 1e9 + ;
  47. const int INF = 0x3f3f3f3f;
  48. const int MAXN = ;
  49. const int xi[] = {, , , -};
  50. const int yi[] = {, -, , };
  51.  
  52. int N, T;
  53. ll a[], b[];
  54. ll c[], d[];
  55. struct asort {
  56. int num;
  57. ll date;
  58. } sa[], sb[];
  59. bool cmp(asort a, asort b) {
  60. return a.date > b.date;
  61. }
  62. int main() {
  63. //freopen("in.txt", "r", stdin);
  64. int t, n, k;
  65. scanf("%d", &t);
  66.  
  67. while(t--) {
  68. ll sum = ;
  69. scanf("%d", &n);
  70.  
  71. for(int i = ; i < n; i++) a[i] = read();
  72. for(int i = ; i < n; i++) b[i] = read();
  73. for(int i = n; i < *n ; i++) {
  74. a[i] = a[i-n];
  75. b[i] = b[i-n];
  76. }
  77. for(int i = ; i < n; i++) {
  78. sum += a[i]*a[i];
  79. sum += b[i]*b[i];
  80. sa[i].num = i, sa[i].date = a[i];
  81. sb[i].num = i, sb[i].date = b[i];
  82. }
  83. sort(sa, sa+n, cmp);
  84. sort(sb, sb+n, cmp);
  85. int m = min(n, );
  86. ll res = ;
  87. for(int ai = ; ai < m; ai++) {
  88. ll ans = ;
  89. int i = (sb[].num - sa[ai].num + n)%n;
  90. for(int j = i; j < n+i; j++) {
  91. ans += (a[j-i]*b[j]) <<;
  92. }
  93. if(ans > res) {
  94. res = ans;
  95. k = i;
  96. }
  97. }
  98. printf("%lld\n", sum - res);
  99. // printf("%d\n", k);
  100. }
  101. return ;
  102. }
  1.  

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. 两种设计模式(1)==>>“简单工厂”

    我们以做一个计算器为例,给大家介绍简单工厂的应用: 效果: 这里我们使用 继承 ,虚方法, 简单工厂的设计模式来完成 首先,我们除了搭好窗体外,我们应该把我们的一些类准备好: 1.计算的父类Calcu ...

  2. cas与NGINX整合(转)

    CAS (5) -- Nginx代理模式下浏览器访问CAS服务器配置详解 标签: 服务器 2015-12-18 15:04 1633人阅读 评论(0) 收藏 举报  分类: 网络(61)    目录( ...

  3. Angularjs,WebAPI 搭建一个简易权限管理系统 —— WebAPI项目主体结构(四)

    目录 前言 Angularjs名词与概念 Angularjs 基本功能演示 系统业务与实现 WebAPI项目主体结构 Angularjs 前端主体结构 5.0 WebAPI项目主体结构 5.1 总体结 ...

  4. dbcp/c3p0连接池设置mysql会话变量

    我们有几个计算风控值的定时任务,几乎每隔5秒会更新所有账户的当前总资产并以此通知风控,每隔一小时就产生一两个G的binlog,几十台服务器折腾..数据库是公用的,代码是通过工具自动生成的,直接修改流程 ...

  5. play framework学习笔记之 模板引擎

    模板语法 ${client.name} ${client?.name} 不能确定client是否存在的时候? #{extends /} #{doLayout /}#{get} #{set} 比如 #{ ...

  6. django使用笔记

    django的具体使用可以看官方手册http://djangobook.py3k.cn,这里主要记录使用django中遇到的问题. 1.中文编码问题. 因为我们用到的东西基本上都有中文,在settin ...

  7. Vue基础理论

    一 vue的定位 (1)Vue.js是一个构建数据驱动的 web 界面的库. (2)Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件. (3)Vue.js 自身不是一 ...

  8. 人人都应该学习Markdown

    Markdown是一门新兴的标记语言,已经有12年历史了.随着它在全球范围内的流行,很多人已经听说.熟识或者开始使用了. 首先,Markdown既不是工具,也不是程序语言,而是一种十分轻量级的标记语言 ...

  9. Oracle学习之简单查询

    使用scott用户下的表, 1.查询所有内容SELECT * FROM emp; 2.查询员工信息,包括员工编号,姓名,职位3个信息SELECT empno,ename,job FROM emp; 3 ...

  10. Xcode注释插件 VVDocumenter 升级Xcode6.x 失效的解决办法

    失效的原因其实是因为在插件的uuid列表中缺少自己的uuid,解决办法如下; 1,打开终端 输入命令: defaults read /Applications/Xcode.app/Contents/I ...