Pagini recente » Cod sursa (job #1299230) | Cod sursa (job #1901138) | Cod sursa (job #2253854) | Cod sursa (job #626573) | Cod sursa (job #520283)
Cod sursa(job #520283)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("patrate3.in");
ofstream g("patrate3.out");
int N,nrt;
struct point { double x,y; }a[1001];
bool cmp(point a,point b)
{ if(a.x<b.x) return 1;
if(a.x==b.x && a.y<b.y) return 1;
return 0;
}
bool bin_search(point s)
{ int left,right,mid;
left=1 , right=N;
while(left<=right)
{ mid=(left+right)>>1;
if(a[mid].x==s.x && a[mid].y==s.y) return 1;
if(s.x<a[mid].x || s.y<a[mid].y) right=mid-1;
else if(a[mid].x<s.x || a[mid].y<s.y) left=mid+1;
}
return 0;
}
int main()
{ int i,j;
point b,d;
f>>N;
for(i=1;i<=N;i++)
f>>a[i].x>>a[i].y;
sort(a+1,a+N+1,cmp);
for(i=1;i<=N;i++)
for(j=i+1;j<=N;j++)
{ d.x=(a[i].x+a[j].x+a[i].y-a[j].y)/2;
d.y=(a[i].y+a[j].y+a[j].x-a[i].x)/2;
if(!bin_search(d)) continue;
b.x=(a[i].x+a[j].x+a[j].y-a[i].y)/2;
b.y=(a[i].y+a[j].y+a[i].x-a[j].x)/2;
if(!bin_search(b)) continue;
nrt++;
}
g<<nrt/2;
f.close();
g.close();
return 0;
}