Pagini recente » Cod sursa (job #675355) | Cod sursa (job #2947177) | Cod sursa (job #2982463) | Cod sursa (job #1802306) | Cod sursa (job #805264)
Cod sursa(job #805264)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#define S3 1.7320508075
#define my pair<int, int>
using namespace std;
int N;
my a[1515];
struct cmp
{
bool operator()(const my &a, const my &b)const
{
if (a.first == b.first)
{
return a.second < b.second;
}
return a.first < b.first;
}
};
inline bool egal(int a, int b)
{
int x = a - b;
if (-150 <= x && x <= 150) return true;
return false;
}
inline bool mic(my a, my b)
{
if (egal(a.first, b.first))
{
if (egal(a.second, b.second))
{
return 1;
}
return a.second < b.second;
}
return a.first < b.first;
}
inline bool bs(my num)
{
int i = 0, cnt = 1 << 12;
for (; cnt > 0; cnt >>= 1)
{
if (i + cnt <= N)
{
if (mic(a[i + cnt], num))
{
i += cnt;
}
}
}
if (egal(a[i].first, num.first) && egal(a[i].second, num.second)) return true;
return false;
}
int main()
{
ifstream fin("triang.in");
ofstream fout("triang.out");
fin >> N;
for (register int i = 1; i <= N; ++i)
{
pair<double, double> c;
fin >> c.first >> c.second;
a[i].first = c.first * 1000000;
a[i].second = c.second * 1000000;
}
sort(a + 1, a + N + 1, cmp());
//for (int i = 1; i <= N; ++i)
//{
// cout << a[i].first << ' ' << a[i].second << '\n';
//}
//cout << "\n\n\n\n";
int gg = 0;
for (int i = 1; i < N; ++i)
{
for (int j = i + 1; j <= N; ++j)
{
my abc;
int sl, sc;
abc.first = (a[i].first + a[j].first) / 2;
abc.second = (a[i].second + a[j].second) / 2;
sl = abc.first - a[j].first;
sc = abc.second - a[j].second;
my one, two;
one = abc;
two = abc;
one.first = one.first + S3 * sc;
one.second = one.second - S3 * sl;
two.first = two.first - S3 * sc;
two.second = two.second + S3 * sl;
//cout << "one " << one.first << ' ' << one.second << '\n';
//cout << "two " << two.first << ' ' << two.second << '\n';
if (bs(one)) ++gg;
if (bs(two)) ++gg;
}
}
fout << gg / 3 << '\n';
fout.close();
}