CodeForces 1500A Going Home|思维

题目链接

题意:
给出\(a\),需要找到四个坐标使 \(a_x+a_y=a_z+a_w\)
\(4\le n\le 2\times 10^5\) \(1\le a_i\le 2.5\times 10^6\)

题目思路:
tmd太离谱了
对于\(a_x+a_y\),必小于\(5 \times 10^6\)
故枚举 \(5 \times 10^6 +1\) 次,必有答案。不会超时,枚举即可。
跑的飞快

#include<bits/stdc++.h>
using namespace std;
int n,a[200100];
struct po
{
	int x,y;
}p[9000000];
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	  cin>>a[i];
	for (int i=1;i<=n;i++)
	{
		for (int j=i+1;j<=n;j++)
		{
			if (i!=j) 
			{
				int cnt=a[i]+a[j];
				if ((p[cnt].x||p[cnt].y)&&(p[cnt].y!=i&&p[cnt].y!=j&&p[cnt].x!=i&&p[cnt].x!=j))
				{
					 cout<<"YES\n"<<p[cnt].x<<" "<<p[cnt].y<<" "<<i<<" "<<j<<endl;
					 return 0;
				}
				else p[cnt].x=i,p[cnt].y=j;
			}
		}
	}
	cout<<"NO\n";
	return 0;
}

没有题出可以不出(无能狂怒)

posted @ 2021-03-17 22:08  fmj_123  阅读(133)  评论(0编辑  收藏  举报