King of Karaoke

Time Limit: 1 Second Memory Limit: 65536 KB

It's Karaoke time! DreamGrid is performing the song Powder Snow in the game King of Karaoke. The song performed by DreamGrid can be considered as an integer sequence \(D_1, D_2, \dots, D_n\), and the standard version of the song can be considered as another integer sequence \(S_1, S_2, \dots, S_n\). The score is the number of integers \(i\) satisfying \(1 \le i \le n\) and \(S_i = D_i\).

As a good tuner, DreamGrid can choose an integer \(K\) (can be positive, 0, or negative) as his tune and add \(K\) to every element in \(D\). Can you help him maximize his score by choosing a proper tune?

Input

There are multiple test cases. The first line of the input contains an integer \(T\) (about 100), indicating the number of test cases. For each test case:

The first line contains one integer \(n\) (\(1 \le n \le 10^5\)), indicating the length of the sequences \(D\) and \(S\).

The second line contains \(n\) integers \(D_1, D_2, \dots, D_n\) (\(-10^5 \le D_i \le 10^5\)), indicating the song performed by DreamGrid.

The third line contains \(n\) integers \(S_1, S_2, \dots, S_n\) (\(-10^5 \le S_i \le 10^5\)), indicating the standard version of the song.

It's guaranteed that at most 5 test cases have \(n > 100\).

Output

For each test case output one line containing one integer, indicating the maximum possible score.

Sample Input

2

4

1 2 3 4

2 3 4 6

5

-5 -4 -3 -2 -1

5 4 3 2 1

Sample Output

3

1

Hint

For the first sample test case, DreamGrid can choose \(K = 1\) and changes \(D\) to \(\{2,3,4,5\}\).

For the second sample test case, no matter which \(K\) DreamGrid chooses, he can only get at most 1 match.

【题意】:通过在第一个序列中的每个元素增加k/减去k/不变来最大化分数,分数为上下序列对应相等的个数。

#include<bits/stdc++.h>

using namespace std;
int a[1000005];
int b[1000005];
vector<int> str;
map<int,int> mp;
int main()
{
int t,n,num;
cin>>t;
while(t--){
int f=1;
cin>>n;
mp.clear();
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
for(int i=0;i<n;i++){
if(a[i]!=b[i]) f=0; }
if(f) cout<<n<<endl;
if(!f){
for(int i=0;i<n;i++){
mp[b[i]-a[i]]++; //map里面int可以放负数作为value-key
}
num=0;
int Max=0;
for(map<int,int>::iterator it = mp.begin();it!=mp.end();it++)
if(it->second > num)
{
num = it->second;
}
cout<<num<<endl;
}
} }
/*
sort(v.begin(),v.end(),less<int>());
num=v[0];
int count=1,min_num=v[0],min_count=1;
for(i=1;i<N-1;i++)
{
if(v[i]>v[i-1])
{
count=1;
if(count>min_count)
min_num=v[i];
}
else if(v[i]==v[i-1])
{
count++;
if(count>min_count)
{
min_count=count;
min_num=v[i];
}
}
} if(v[N-1]==min_num)
min_count++; cout<<min_num<<min_count<<endl; /*
sort(v.begin(),v.end());
int Max=0,num=1,value=v[0],pre=v[0];
int cur;
//-1 -1 -1 2
for(int i=1;i<v.size();i++){
cur=v[i];
if(cur==pre) num++;
else{
if(num>Max){
Max=num;
value=pre;
}
num=1;
pre=cur;
}
}
cout<<Max<<endl;
*/ /*
int Max=1;
for(int i=0;i<n;i++){
num = count(v.begin(),v.end(),a[i]);
Max=max(num,Max);
}
*/

King of Karaoke的更多相关文章

  1. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke

    King of Karaoke Time Limit: 1 Second      Memory Limit: 65536 KB It's Karaoke time! DreamGrid is per ...

  2. [ZOJ 4025] King of Karaoke

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5766 求两个序列的相对元素的差出现次数最多的,最低出现一次. AC代 ...

  3. The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)

    ZOJ 4024 Peak 题意 给出n和n个数,判断该数列是否是凸形的. 解题思路 从前往后第一对逆序数,和从后往前第一队逆序数,如果都非零而且相邻,证明该数组是凸形的. 代码 #include & ...

  4. 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple

    我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...

  5. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  6. [bzoj1087][scoi2005]互不侵犯king

    题目大意 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上 左下右上右下八个方向上附近的各一个格子,共8个格子. 思路 首先,搜索可以放弃,因为这是一 ...

  7. King's Quest —— POJ1904(ZOJ2470)Tarjan缩点

    King's Quest Time Limit: 15000MS Memory Limit: 65536K Case Time Limit: 2000MS Description Once upon ...

  8. 【状压DP】bzoj1087 互不侵犯king

    一.题目 Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上.下.左.右,以及左上.左下.右上.右下八个方向上附近的各一个格子,共8个格子. I ...

  9. ZOJ 2334 Monkey King

    并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子                       Monkey King ...

随机推荐

  1. js实现类bootstrap模态框动画

    在pc端开发,模态框是一个很常用的插件,之前一直用的第三方插件,比如bootstrap,jQuery的模态框插件,最近还用了elementUI的.但是会发现其实动画效果都差不多,那么如何去实现这样一个 ...

  2. Python全栈工程师(每周总结:2)

     ParisGabriel   感谢 大家的支持                                                               每天坚持 一天一篇 点个订 ...

  3. 斐波那契数列的三种C++实现及时间复杂度分析

    本文介绍了斐波那契数列的三种C++实现并详细地分析了时间复杂度. 斐波那契数列定义:F(1)=1, F(2)=1, F(n)=F(n-1) + F(n-2) (n>2) 如何计算斐波那契数 F( ...

  4. hnust py road

    问题 C: Py Road 时间限制: 1 Sec  内存限制: 128 MB提交: 125  解决: 34[提交][状态][讨论版] 题目描述 Life is short,you need Pyth ...

  5. 聊聊、Mybatis XML

    引入相应的依赖包 <dependency><groupId>org.mybatis</groupId><artifactId>mybatis-sprin ...

  6. python爬取动态网页2,从JavaScript文件读取内容

    import requests import json head = {"user-agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) ...

  7. BETA0

    目录 过去存在的问题 任务分工 规范 后端总结 卉卉 家灿 前端总结 绪佩 青元 恺琳 宇恒 丹丹 算法&API接口 家伟 鸿杰 一好 文档&博客撰写 政演 产品功能 我们已经坐了哪些 ...

  8. c# 对XML 解析 和 序列化

    /// <summary> /// 解析XML 数据 /// </summary> /// <param name="re"></para ...

  9. 第十三篇:HTML

    本篇内容 选择器 属性 一. 选择器 1.id 选择器 id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式. id 选择器以 "#" 来定义. <!DOCTY ...

  10. ACM ICPC China final G Pandaria

    目录 ACM ICPC China final G Pandaria ACM ICPC China final G Pandaria 题意:给一张\(n\)个点\(m\)条边的无向图,\(c[i]\) ...