B - King of Karaoke 8102浙江省赛 zoj 水题

直接用map判重 或者 用数组判重 

数组判重的范围是1e5*4  为毛?

+-1e5   +-1e5

总和就是 4e5

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;

const int maxn=1e5+2000;
int d[maxn],s[maxn];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		map<int,int> m;
		int n;
		scanf("%d",&n);
		memset(d,0,sizeof(d));
		memset(s,0,sizeof(s));
		int sum=1;	
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&d[i]);
		}
		for(int i=1;i<=n;i++)
		{
			int x;
			scanf("%d",&x);
			m[d[i]-x]+=1;
			if(m[d[i]-x]>sum) sum=m[d[i]-x];
		}
		/*
		for(int i=1;i<=n;i++)
		{
			cha[i]=s[i]-d[i];
		}
		sort(cha+1,cha+n+1);
		int sum=0,temp=1;
		for(int i=2;i<=n;i++)
		{
			if(cha[i]==cha[i-1])
			{
				temp++;
				sum=max(sum,temp);
			}
			else
			{
				temp=1;
				sum=max(sum,temp);
			}
		}*/
		printf("%d\n",sum);
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_41544329/article/details/83508433
今日推荐