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. CentOS 单用户模式:修改Root密码和grub加密[转]

    原文出处: http://zhengdl126.iteye.com/blog/430268 Linux 系统处于正常状态时,服务器主机开机(或重新启动)后,能够由系统引导器程序自动引导 Linux 系 ...

  2. Java 注解(Annoation)学习笔记

    1 Junit中的@Test为例: 1.1 用注解(@Test)前 private boolean isTestMethod(Method m) { return m.getParameterType ...

  3. Activiti入门 -- 轻松解读数据库

    相关文章: <史上最权威的Activiti框架学习指南> <Activiti入门 --环境搭建和核心API简介> 在Activiti中,相对前身JBPM基础上又额外多了5张,框 ...

  4. DOS程序员手册(一)

    当今MS-Windows横扫大江南北,让我们这就来研究一下它的祖宗——MS-DOS! 这本书很难得,希望读者好好学习! DOS程序员手册(一) DOS教程 (以下内容全部为原作者的阐述,照样保留) 这 ...

  5. 【vim环境配置】在centos6.4上配置vim的一些零碎记录

    上一篇日志已经step by step地实录了如何在本机mac上配置vim开发环境已经各种插件. 有了一定经验之后,开始在实验室远程server上centos6.4的环境下配置vim环境. 这台机器是 ...

  6. XSS注入常用语句积累

    <script>alert('hello,gaga!');</script> //经典语句,哈哈! >"'><img src="javas ...

  7. 每天一个Linux命令(5):rm命令

    rm命令可以删除一个目录中的一个或多个文件或目录,也可以将某个目录及其下属的所有文件及其子目录均删除掉.对于链接文件,只是删除整个链接文件,而原有文件保持不变. 语法 rm (选项)(参数) 选项 - ...

  8. reinterpret_cast and const_cast

    reinterpret_cast reinterpret意为“重新解释” reinterpret_cast是C++中与C风格类型转换最接近的类型转换运算符.它让程序员能够将一种对象类型转换为另一种,不 ...

  9. CocoaPods 安装与使用

    1.如果之前已经安装过的 gem list --local | grep cocoapods 会看到如下输出: cocoapods (1.1.1)cocoapods-deintegrate (1.0. ...

  10. 主流 NoSQL 数据库对比

    HBase HBase 是 Apache Hadoop 中的一个子项目,属于 bigtable 的开源版本,所实现的语言为Java(故依赖 Java SDK).HBase 依托于 Hadoop 的 H ...