Cod sursa(job #1956996)

Utilizator GabiTulbaGabi Tulba-Lecu GabiTulba Data 7 aprilie 2017 11:09:31
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define MaxN 1505
#define MaxM 10007
#define rad3 1.7320508075688772935274463415059
#define eps 0.001
#define PI 3.1415926535897932384626433832795
using namespace std;
  
FILE*IN,*OUT;

int N,cnt=0;
double x,y;
struct Point
{
	long long x,y;
}v[MaxN];
vector <Point>H[MaxM];
void Add(Point p)
{
	long long S=abs(p.x*p.y);
	S%=MaxM;
	H[S].push_back(p);
}
bool Search(long long x,long long y)
{
	long long S=abs(x*y);
	S%=MaxM;
	for(int i=0;i<H[S].size();i++)
		if(abs(H[S][i].x-x)<=eps&&abs(H[S][i].y-y)<=eps)
			return true;
	return false;
}
int main()
{
    IN=fopen("test.in","r");
    OUT=fopen("test.out","w");
	
	fscanf(IN,"%d",&N);
	for(int i=1;i<=N;i++)
	{
		fscanf(IN,"%lf%lf",&x,&y);
		v[i].x=x*2000,v[i].y=y*2000;
		Add(v[i]);
	}
	for(int i=1;i<=N;i++)
		for(int j=i+1;j<=N;j++)
		{
			double dist=pow(pow(v[i].x-v[j].x,2.0)+pow(v[i].y-v[j].y,2.0),0.5);
			double angle=atan2((double)v[j].y-v[i].y,(double)v[j].x-v[i].x);
			long long x=(v[i].x+v[j].x)/2,y=(v[i].y+v[j].y)/2;
			if(Search(x+cos(angle+PI/2)*dist*rad3/2,y+sin(angle+PI/2)*dist*rad3/2))
				cnt++;
			if(Search(x-cos(angle+PI/2)*dist*rad3/2,y+sin(angle+PI/2)*dist*rad3/2))
				cnt++;
		}
	fprintf(OUT,"%d",cnt/3);
    return 0;
}