King of Karaoke
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的更多相关文章
- 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 ...
- [ZOJ 4025] King of Karaoke
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5766 求两个序列的相对元素的差出现次数最多的,最低出现一次. AC代 ...
- The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)
ZOJ 4024 Peak 题意 给出n和n个数,判断该数列是否是凸形的. 解题思路 从前往后第一对逆序数,和从后往前第一队逆序数,如果都非零而且相邻,证明该数组是凸形的. 代码 #include & ...
- 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple
我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- [bzoj1087][scoi2005]互不侵犯king
题目大意 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上 左下右上右下八个方向上附近的各一个格子,共8个格子. 思路 首先,搜索可以放弃,因为这是一 ...
- King's Quest —— POJ1904(ZOJ2470)Tarjan缩点
King's Quest Time Limit: 15000MS Memory Limit: 65536K Case Time Limit: 2000MS Description Once upon ...
- 【状压DP】bzoj1087 互不侵犯king
一.题目 Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上.下.左.右,以及左上.左下.右上.右下八个方向上附近的各一个格子,共8个格子. I ...
- ZOJ 2334 Monkey King
并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子 Monkey King ...
随机推荐
- Android学习记录(9)—Android之Matrix的用法
Matrix ,中文里叫矩阵,高等数学里有介绍,在图像处理方面,主要是用于平面的缩放.平移.旋转等操作. 首先介绍一下矩阵运算.加法和减法就不用说了,对应位相加就好.图像处理,主要用到的是乘法 .下面 ...
- 云计算之路-阿里云上:SLB引起的https访问速度慢问题
自从我们在阿里云SLB上部署了https之后(详见在SLB上部署https遇到的问题及解决方法),陆续有园友向我们反馈登录时速度很慢(登录时是通过https访问),有些园友甚至无法访问登录页面. 而我 ...
- ironic rescue standard rescue and unrescue process
翻译官网救援/取消救援标准流程 1.用户在节点上调用Nova rescue 2.Nova ComputeManager调用virt驱动程序的rescue()方法,传入rescue_password作为 ...
- 课时17:函数:Python的乐高积木
目录: 一.创建和调用函数 二.函数的参数 三.函数的返回值 四.课时17课后习题及答案 为了使得程序得代码变得简单,就需要把程序分解成较小得组成部分.有三种方法可以实现:函数.对象.模块. **** ...
- NVIDIA/DIGITS:Building DIGITS
在 Prerequisites中的 sudo apt-get update命令发生错误: W: GPG 错误:http://developer.download.nvidia.com/compute/ ...
- 推荐系统评测指标--准确率(Precision)和召回率(Recall)、F值(F-Measure)
转自http://bookshadow.com/weblog/2014/06/10/precision-recall-f-measure/ 1,准确率和召回率是广泛应用于信息检索和统计学分类领域的两个 ...
- 更优雅的清除浮动float方法
上篇文章是利用 :after 方法清除浮动float(作用于浮动元素的父元素上). ; } //为了兼容性,因为ie6/7不能使用伪类,所以加上此行代码. .outer:after {;;visibi ...
- 虚机中访问外网;NAT中的POSTROUTING是怎么搞的?
看下docker中是怎么配置的网络 在虚机中访问外网:设定了qemu,在主机上添加路由:sudo iptables -t nat -I POSTROUTING -s 192.168.1.110 -j ...
- Android React Native组件的生命周期及回调函数
熟悉android的童鞋应该都清楚,android是有生命周期的,其很多组件也是有生命周期.今天小编和大家分享的React Native组件的生命周期,还不了解的童鞋,赶紧来围观吧 在android开 ...
- C# 在子窗体调用父窗体的值(转)
1.在父窗体中 public delegate void SetVisiableHandler();//定义委托类型 注意此委托定义在namespace下一级,在form类外 private void ...