Pagini recente » Cod sursa (job #1358355) | Cod sursa (job #1610924) | Cod sursa (job #2565812) | Cod sursa (job #283475) | Cod sursa (job #2178953)
#include <bits/stdc++.h>
using namespace std;
ifstream in("patrate3.in");
ofstream out("patrate3.out");
struct point{
double x, y;
};
int n, cnt;
point P[1010];
bool cmp(const point &a, const point &b){
return (a.x == b.x ? a.y < b.y : a.x < b.x);
}
double hsh(point P){
return 1000000 * (P.x + 12000) + P.y;
}
bool bs(point M){
int st = 1, dr = n, mid;
while(st <= dr){
mid = st + dr >> 1;
if(hsh(P[mid]) <= hsh(M))
st = mid + 1;
else dr = mid - 1;
}
return hsh(P[dr]) == hsh(M);
}
int main(){
in >> n;
for(int i = 1; i <= n; i++)
in >> P[i].x >> P[i].y;
sort(P + 1, P + n + 1, cmp);
for(int i = 1; i < n; i++){
for(int j = i + 1; j <= n; j++){
point M, A, B;
M.x = (P[i].x + P[j].x) / 2;
M.y = (P[i].y + P[j].y) / 2;
double H = abs(P[j].y - M.y);
double L = abs(P[j].x - M.x);
if(P[j].y < P[i].y)
H = -H;
A.x = M.x - H;
A.y = M.y + L;
B.x = M.x + H;
B.y = M.y - L;
if(bs(A) && bs(B))
cnt++;
}
}
out << cnt / 2;
return 0;
}