Pagini recente » Cod sursa (job #1250312) | Cod sursa (job #772878) | Cod sursa (job #49977) | Cod sursa (job #2289125) | Cod sursa (job #2570806)
#include <fstream>
#include <algorithm>
#include <math.h>
#define ios ios_base::sync_with_stdio(false);
#define NMAX 1505
#define ERR 0.001
using namespace std;
int n,i,a,b,sol;
struct p{
double x;
double y;
}puncte[NMAX];
/*ifstream cin ("triang.in");
ofstream cout ("triang.out");*/
bool comp(p p1,p p2){
if (p1.x==p2.x) return p1.y<p2.y;
return p1.x<p2.x;
}
void citire(){
cin>>n;
for (i=1;i<=n;i++)
cin>>puncte[i].x>>puncte[i].y;
sort(puncte+1,puncte+n+1,comp);
}
double abs(double x){
if (x<0) return -x;
return x;}
int cbin(double x,double y){
int st=1, dr=n, mij;
while (st<=dr){
mij=(st+dr)/2;
if (abs(puncte[mij].x-x)<=ERR && abs(puncte[mij].y-y)<=ERR) return 1;
if (puncte[mij].x<x) st=mij+1;
else dr=mij-1;
}
return 0;
}
void rezolvare(){
for (a=1;a<=n;a++)
for (b=a+1;b<=n;b++){
double x1,x2,y1,y2,ym,xm,m,dist;
p p1,p2;
p1.x=puncte[a].x;
p1.y=puncte[a].y;
p2.x=puncte[b].x;
p2.y=puncte[b].y;
xm=(p1.x+p2.x)/2;
ym=(p1.y+p2.y)/2;
//cout<<p1.x<<" "<<p1.y<<" "<<p2.x<<" "<<p2.y<<" "<<xm<<" "<<ym<<'\n';
dist=(p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
//cout<<dist<<'\n';
dist*=3;
//cout<<0.5d*sqrt(dist)<<" "<<p2.x-p1.x<<'\n';
if (abs(p2.x-p1.x)<=ERR){
y1=ym;
y2=ym;
x1=xm+0.5d*sqrt(dist);
x2=xm-0.5d*sqrt(dist);
}
else
{
m=(p2.y-p1.y)/(p2.x-p1.x);
//cout<<m<<'\n';
x1=xm+0.5d*m*sqrt(dist/(m*m+1));
y1=ym-0.5d*sqrt(dist/(m*m+1));
x2=xm-0.5d*m*sqrt(dist/(m*m+1));
y2=ym+0.5d*sqrt(dist/(m*m+1));
}
//cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<'\n';
sol+=cbin(x1,y1);
sol+=cbin(x2,y2);
//cout<<'\n';
}
cout<<sol/3;
}
int main()
{
ios;
cin.tie(0);
cout.tie(0);
citire();
rezolvare();
return 0;
}