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 performing the song Powder Snow in the game King of Karaoke. The song performed by DreamGrid can be considered as an integer sequence , and the standard version of the song can be considered as another integer sequence . The score is the number of integers satisfying and .
As a good tuner, DreamGrid can choose an integer (can be positive, 0, or negative) as his tune and add to every element in . 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 (about 100), indicating the number of test cases. For each test case:
The first line contains one integer (), indicating the length of the sequences and .
The second line contains integers (), indicating the song performed by DreamGrid.
The third line contains integers (), indicating the standard version of the song.
It's guaranteed that at most 5 test cases have .
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 and changes to .
For the second sample test case, no matter which DreamGrid chooses, he can only get at most 1 match.
原题地址:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5753
题意:给你两个数组A,B,问你A数组所有元素同时加一个数或减一个数或不变之后与B数组相同的最大个数;
思路:因为数组A加的数是相同的所以A数组变化之后差值个数还是一样,所以直接计算A数组和B数组之间的差值最多的个数就行,因为可能有负数,所以用map又轻松又简单,map真是个好东西
代码:
#include<bits/stdc++.h>
using namespace std; int a[];
int b[];
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
map<int,int>mp;
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>a[i];
}
for(int i=;i<n;i++){
cin>>b[i];
}
for(int i=;i<n;i++){
mp[a[i]-b[i]]++;
}
int maxn=;
map<int,int>::iterator it;
for(it=mp.begin();it!=mp.end();it++){
if(it->second>maxn){
maxn=it->second;
}
}
cout<<maxn<<endl;
}
return ;
}
最新文章
- c++2008 并行配置文件和获取字典的所有key的方法
- python获取文件大小
- VS2012 MVC4 学习笔记-概览
- 美发帮--android APP开发实战
- IOS APP上下黑边问题
- Android TextView标签的显示
- 【转】DataGridView显示行号
- 五、Socket之UDP异步传输文件-实现传输中取消传送
- BZOJ1264: [AHOI2006]基因匹配Match
- javascript每日一练(三)——DOM一
- HDU 4315 Climbing the Hill [阶梯Nim]
- CSS——LESS【转】
- 第九次作业——K-means算法应用:图片压缩
- 判断文件是否存在,不要用if exist和if not exist,因为他们会受到文件是否隐藏的影响,改用dir /a 命令代替
- 【MySQL】sql_mode引起的一个问题和总结
- radio样式的写法,单选和多选如何快速的改变默认样式,纯CSS,
- hbase的api操作
- 尚学堂java答案解析 第三章
- SQLyog客户端无法连接MySQL服务器
- python练习笔记——map | sum | pow 的应用
热门文章
- [poj 2274]后缀数组+最长公共子串
- 安卓sdk安装教程
- js获取当前url地址参数中文乱码问题
- Restful 接口权限控制
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method &#39;GET&#39; not supported解决!
- Navicat Premium mysql
- openlayers3中应用proj4js
- codeforces B. Okabe and Banana Trees 结论题
- 【HDU】6146 Pok&#233;mon GO
- 160多条Windows 7 “运行”命令