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. 《Cracking the Coding Interview》——第14章:Java——题目4

    2014-04-26 19:02 题目:解释下C++里模板和java里泛型的区别? 解法:我很少用java,属于连语法都不过关的程度.所以这个题还真没法详细答,查了些资料以后写了以下几点. 代码: / ...

  2. 《Cracking the Coding Interview》——第1章:数组和字符串——题目3

    2014-03-18 01:32 题目:对于两个字符串,判断它们是否是Anagrams. 解法:统计俩单词字母构成是否相同即可. 代码: // 1.3 Given two strings, write ...

  3. linux文件上传下载笔记(rz,sz,sftp,scp)命令

    软件(包)安装/卸载 yum -y install 包名(支持*) :自动选择y,全自动yum install 包名(支持*) :手动选择y or nyum remove 包名(不支持*)rpm -i ...

  4. Python爬虫教程

    Python爬虫(1):基本原理 Python爬虫(2):Requests的基本用法 Python爬虫(3):Requests的高级用法 Python爬虫(4):Beautiful Soup的常用方法 ...

  5. StringBuilder_学习笔记

    参考:https://www.jianshu.com/p/160c9be0b132 连接符号 "+" 本质 字符串变量(非final修饰)通过 "+" 进行拼接 ...

  6. sqlserver 汉字转拼音 索引 函数

    IF OBJECT_ID('[fn_GetPinyin]') IS NOT NULL DROP FUNCTION [fn_GetPinyin] GO create function [dbo].[fn ...

  7. 【bzoj4177】Mike的农场 网络流最小割

    题目描述 Mike有一个农场,这个农场n个牲畜围栏,现在他想在每个牲畜围栏中养一只动物,每只动物可以是牛或羊,并且每个牲畜围栏中的饲养条件都不同,其中第i个牲畜围栏中的动物长大后,每只牛可以卖a[i] ...

  8. C#类和类成员初始化顺序

    1.不带静态成员的普通类,首先通过构造函数初始化. 2.带静态属性的类,无论是普通类还是静态类,都会先初始化静态字段,再执行构造函数. 3.类初始化时,不会执行类中方法,无论是否是静态.若想执行方法, ...

  9. [洛谷P3805]【模板】manacher算法

    题目大意:给你一个字符串,求出它的最长回文字段 题解:$manacher$算法 卡点:$p$数组未开两倍空间 C++ Code: #include <cstdio> #include &l ...

  10. BZOJ4652 [Noi2016]循环之美 【数论 + 莫比乌斯反演 + 杜教筛】

    题目链接 BZOJ 题解 orz 此题太优美了 我们令\(\frac{x}{y}\)为最简分数,则\(x \perp y\)即,\(gcd(x,y) = 1\) 先不管\(k\)进制,我们知道\(10 ...