Pagini recente » Cod sursa (job #480444) | Cod sursa (job #1275077) | Cod sursa (job #1909492) | Cod sursa (job #1089350) | Cod sursa (job #1065480)
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct Point
{
double x,y;
bool operator()(Point A,Point B)
{
if(A.x==B.x) return (A.y<B.y);
return (A.x<B.x);
}
};
int N,sol;
Point P[1005],A,B;
inline double dist(Point A,Point B)
{
return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));
}
void determine(Point A,Point &B,Point C,Point &D)
{
double mAC,mBD,nBD,d,a,b,c;
Point M;
M.x=(A.x+C.x)/2;
M.y=(A.y+C.y)/2;
if(A.x != C.x && A.y != C.y)
{
mAC=(A.y-C.y)/(A.x-C.x);
mBD=-1/mAC;
a=mAC;
b=-1;
c=A.y-mAC*A.x;
d=dist(A,M)*sqrt(a*a+b*b);
nBD=M.y-mBD*M.x;
B.x=(d-b*nBD-c)/(a+b*mBD);
B.y=mBD*B.x+nBD;
D.x=(-d-b*nBD-c)/(a+b*mBD);
D.y=mBD*D.x+nBD;
}
}
inline bool equals(double A,double B)
{
return ((A-B)<1e-4 && (B-A)<1e-4);
}
bool binary_s(Point A)
{
int st=1,dr=N,md;
for(;st<=dr;)
{
md=(st+dr)/2;
if(equals(A.x,P[md].x) && equals(A.y,P[md].y)) return 1;
if((A.x) < (P[md].x)) {dr=md-1; continue;}
if((A.x) > (P[md].x)) {st=md+1; continue;}
if(equals(A.x,P[md].x) && (A.y) < (P[md].y)) {dr=md-1; continue;}
if(equals(A.x,P[md].x) && (A.y) > (P[md].y)) {st=md+1; continue;}
}
return 0;
}
int main()
{
int i,j;
freopen("patrate3.in","r",stdin);
freopen("patrate3.out","w",stdout);
scanf("%d",&N);
for(i=1;i<=N;i++)
scanf("%lf%lf",&P[i].x,&P[i].y);
sort(P+1,P+N+1,Point());
for(i=1;i<=N;i++)
for(j=i+1;j<=N;j++)
{
determine(P[i],A,P[j],B);
if(binary_s(A) && binary_s(B)) sol++;
}
printf("%d\n",sol/2);
return 0;
}