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. 通过重写ViewGroup学习onMeasure()和onLayout()方法

    在继承ViewGroup类时,需要重写两个方法,分别是onMeasure和onLayout. 1,在方法onMeasure中调用setMeasuredDimension方法 void android. ...

  2. 4G来临,短视频社交分享应用或井喷

    因为工作的原因,接触短视频社交应用的时间相对较多,不管是自家的微视,还是别人家的Vine.玩拍.秒拍等,都有体验过.随着时间的推移,我愈发感受到有一股似曾相识的势能正在某个地方慢慢积聚,直到今天我才猛 ...

  3. python学习笔记十三:Flask demo

    一.Flask简介 Flask 是一个 Python 实现的 Web 开发微框架.官网:http://flask.pocoo.org/ 二.Demo 1.代码结构 . ├── blog.py ├── ...

  4. Linux忘记root密码的解决办法

    这里以centos6为例: 第一步:先将系统重新启动,在读秒的时候按下任意键就会出现如下图的菜单界面: 第二步:按下『e』就能够进入grub的编辑模式,如图: 第三步:将光标移动到kernel那一行, ...

  5. ssh.sh_for_ubuntu1404

    #!/bin/bash sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config s ...

  6. Ubuntu16.04安装openCV的问题集合

    Q1 下列软件包有未满足的依赖关系:   libtiff4-dev : 依赖: libjpeg-dev  E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系. 上网查了 ...

  7. GYM - 101147 B.Street

    题意: 大矩形代表市场,大矩形当中有很多小矩形样式的伞.这些小矩形都贴着大矩形的左边或者右边且互不相交.小矩形以外的地方都是阳光.求经过大矩形时在阳光下的最短时间. 题解: 最短路的做法.起点和终点与 ...

  8. UVA 11478(差分约束 + 二分)

    题意: 给定一个有向图,每条边都有一个权值,每次你可以选择一个结点和一个整数的,把所有以v为终点的边的权值减去d, 把所有以v为起点的边的权值加上d 最后要让所有边的权的最小值非负且尽量大 代码 #i ...

  9. BZOJ1055[HAOI2008]玩具取名 【区间dp + 记忆化搜索】

    题目 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后 他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够 ...

  10. 洛谷 P3168 [CQOI2015]任务查询系统 解题报告

    P3168 [CQOI2015]任务查询系统 题目描述 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分. 超级计算机中的任务用三元组\((S_i,E_i,P_i) ...