King of Karaoke ZOJ - 4025

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.


题意:输入两个序列,在a序列上加上同一个数num,得到的序列与b序列对应位置最多会有几个相同的。 


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
const int maxn = 100010;
int mapp1[maxn];
int mapp2[maxn];
int sum[maxn];
int n;
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int maxn = 0;
        int b = 0;
        scanf("%d", &n);
        //输入a序列;
        for(int i=0; i<n; i++)
        {
            scanf("%d", &mapp1[i]);
        }
        //输入b序列,并且计算出每个对应位置的差值sum[i];
        for(int i=0; i<n; i++)
        {
            scanf("%d", &mapp2[i]);
            sum[i] = mapp1[i]-mapp2[i];
        }
        //对sum数组进行排序,目的是把相同的放在一起;
        sort(sum, sum+n);
        //b用来记录每种sum[i]的个数,再用k进行最大值的比较;
        for(int i=1; i<n; i++)
        {
            if(sum[i]==sum[i-1])
                b++;
            if(sum[i]!=sum[i-1])
                b = 0;
            if(b>maxn)
                maxn = b;
        }
        printf("%d\n",maxn+1);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值