当前位置:网站首页>(lightoj - 1410) consistent verbs (thinking)

(lightoj - 1410) consistent verbs (thinking)

2022-07-06 07:38:00 AC__ dream

Topic link :Consistent Verdicts | LightOJ

The question : There are... On a plane n personal , give n Personal position , Everyone has a grab , And everyone will shoot a bullet , this n Individuals can hear gunshots at the same distance , Give at random n A number represents the gunshot that everyone can hear except himself , this n A number may or may not be legal , Now ask the total number of legal schemes ?

This question is actually a thinking question , Direct thinking is not easy to solve problems , We just want to , If the distance everyone hears is limited , Then the answer is fixed , But there may be multiple distances corresponding to the same situation , For example, when the distance between everyone is greater than 1000 when , So if everyone hears the distance is 0~1000, Then everyone hears the gunshot 0, Therefore, it is not difficult for us to think , When the distance between all people increases in order ( After removing the repeated distance ) Arranged as a[1],a[2],……, Then the distance to hear the sound is 0~a[1]-1,a[1]~a[2]-1,…… Each corresponds to a legal scheme , in other words The number of different distances between people plus 1 Is the answer , This can be well understood , The idea is still quite wonderful

Here is the code :

#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
#define int long long
const int N=703;
vector<int>alls;
int x[N],y[N];
signed main()
{
	int T;
	cin>>T;
	for(int _=1;_<=T;_++)
	{
		int n;
		scanf("%lld",&n);
		for(int i=1;i<=n;i++)
			scanf("%lld%lld",&x[i],&y[i]);
		alls.clear();
		for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			alls.push_back((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
		sort(alls.begin(),alls.end());
		alls.erase(unique(alls.begin(),alls.end()),alls.end());
		printf("Case %lld: %lld\n",_,alls.size()+1);
	}
	return 0;
}

原网站

版权声明
本文为[AC__ dream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131910563635.html