Pagini recente » Cod sursa (job #2517190) | Cod sursa (job #99440) | Cod sursa (job #3273182) | Cod sursa (job #927404) | Cod sursa (job #1299651)
#include <fstream>
#include <unordered_set>
#include <math.h>
#include <set>
#define MAXN 1505
#define EPS 0.0001
using namespace std;
ifstream f("triang.in");
ofstream g("triang.out");
bool is_equal(double a, double b){
return fabs(a - b) < EPS;
}
struct Comp{
bool operator()(pair<double, double> a, pair<double, double> b){
if(is_equal(a.first, b.first)){
if(is_equal(a.second, b.second))
return 0;
return a.second < b.second;
}
return a.first < b.first;
}
};
int n, sol;
pair<double, double> v[MAXN];
//unordered_set<pair<double, double> > v_hash;
set< pair<double, double>, Comp> v_hash;
void rotate(pair<double, double> &p, double u){
double x = p.first, y = p.second;
p.first = x * cos(u) - y * sin(u);
p.second = x * sin(u) + y * cos(u);
}
void solve(pair<double, double> p1, pair<double, double> p2){
pair<double, double> p2t = make_pair(p2.first - p1.first, p2.second - p1.second);
pair<double, double> p3;
double u = atan2(p2t.second, p2t.first);
rotate(p2t, -u);
p3.first = p2t.first / 2;
p3.second = sqrt(3 * (p2t.first * p2t.first + p2t.second * p2t.second)) / 2;
rotate(p3, u);
p3.first += p1.first; p3.second += p1.second;
if(v_hash.find(p3) != v_hash.end())
sol++;
p3.first = p2t.first / 2;
p3.second = -sqrt(3 * (p2t.first * p2t.first + p2t.second * p2t.second)) / 2;
rotate(p3, u);
p3.first += p1.first; p3.second += p1.second;
if(v_hash.find(p3) != v_hash.end())
sol++;
}
int main(){
int i, j;
f >> n;
for(i = 1; i <= n; i++){
f >> v[i].first >> v[i].second;
for(j = 1; j < i; j++)
solve(v[i], v[j]);
v_hash.insert(v[i]);
}
g << sol / 2 << '\n';
f.close();
g.close();
return 0;
}