Description
给出两个长度均为 n n 的序列和 b b ,先可以给序列每个元素加一个常数,问加完常数后这两个序列相同的位置数最大值
Input
第一行一整数 T T 表示用例组数,每组用例首先输入一整数表示序列长度,之后输入 n n 个整数表示 a a 序列,最后输入个整数 b1,...,bn b 1 , . . . , b n 表示 b b 序列
Output
对于每组用例,输出加完常数的 a a 序列和序列相同位置数的最大值
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
Solution
简单题, bi−ai b i − a i 的众数即为答案
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100005;
int T,n,a[maxn],b[maxn];
map<int,int>M;
map<int,int>::iterator it;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++)scanf("%d",&b[i]);
M.clear();
for(int i=1;i<=n;i++)M[a[i]-b[i]]++;
int ans=0;
for(it=M.begin();it!=M.end();it++)ans=max(ans,it->second);
printf("%d\n",ans);
}
return 0;
}