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.
题目链接:King of Karaoke
题意:第一行是DG唱卡拉OK的得分,第二行是原唱的得分,现在DG可以对每个数同时加上一个数k(k可以是正或负或0),问最后DG最多能得多少分。得分的条件是两个序列对应位置的数字相等。
解题思路:
计算两个序列对应位置的差值保存在数组c中,排下序找下这个数组中最多有多少个相同的数字,输出即可。
AC代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100010],b[100010],c[100010];
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
for(int i=0;i<n;i++)
{
c[i]=b[i]-a[i];
}
sort(c,c+n);
// for(int i=0;i<n;i++)
// {
// printf("%d ",c[i]);
// }
// printf("\n*********\n");
int f=c[0],maxx=-1,sum=0;
for(int i=0;i<n;i++)
{
if(c[i]==f)
{
sum++;
if(sum>maxx)
{
maxx=sum;
}
}
else
{
f=c[i];
sum=1;
}
}
printf("%d\n",maxx);
}
return 0;
}
/*
1
4
1 1 1 1
1 1 1 1
*/