Pagini recente » Cod sursa (job #1078141) | Cod sursa (job #2465160) | Cod sursa (job #1136137) | Cod sursa (job #1073611)
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iterator>
#include <assert.h>
using namespace std;
const string file = "patrate3";
const string infile = file + ".in";
const string outfile = file + ".out";
const int INF = 0x3f3f3f3f;
struct Point
{
double x;
double y;
};
bool pred(const Point& a, const Point& b)
{
if(a.x != b.x)
{
return a.x < b.x;
}
else
{
return a.y < b.y;
}
}
bool Contains(vector<Point>& points, Point& toSearch)
{
int left = 0;
int right = points.size() - 1;
while(left <= right)
{
int mid = (left + right) / 2;
Point& midP = points[mid];
if(abs(toSearch.x - midP.x) <= 0.0001 && abs(toSearch.y - midP.y) <= 0.0001)
{
return true;
}
bool comp = pred(toSearch, midP);
if(comp == true)
{
right = mid - 1;
}
else
{
left = mid + 1;
}
}
return false;
}
int main()
{
#ifdef ONLINE_JUDGE
ostream &fout = cout;
istream &fin = cin;
#else
fstream fout(outfile.c_str(), ios::out);
fstream fin(infile.c_str(), ios::in);
#endif
int N;
fin >> N;
vector<Point> points(N);
for(int i = 0; i < N; i++)
{
fin >> points[i].x >> points[i].y;
}
sort(points.begin(), points.end(), pred);
int Sol = 0;
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
if(i == j)
continue;
Point& a = points[i];
Point& b = points[j];
Point mid;
mid.x = (a.x + b.x)/2;
mid.y = (a.y + b.y)/2;
double dx = abs(mid.x - a.x);
double dy = abs(mid.y - a.y);
if(a.y < b.y)
{
Point ul;
ul.x = mid.x + dy;
ul.y = mid.y - dx;
Point lr;
lr.x = mid.x - dy;
lr.y = mid.y + dx;
if(Contains(points, ul) && Contains(points, lr))
Sol++;
}
else
{
Point ur;
ur.x = mid.x + dy;
ur.y = mid.y + dx;
Point ll;
ll.x = mid.x - dy;
ll.y = mid.y - dx;
if(Contains(points, ur) && Contains(points, ll))
Sol++;
}
}
}
fout << Sol/2 << "\n";
#ifdef ONLINE_JUDGE
#else
fin.close();
fout.close();
#endif
}