Pagini recente » Cod sursa (job #773941) | Cod sursa (job #999619) | Cod sursa (job #389328) | Cod sursa (job #479025) | Cod sursa (job #1479732)
#include <fstream>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <unordered_set>
#include <cmath>
using namespace std;
constexpr double epsilon = 1e-3;
double eq(const double a, const double b){
return (a < b) ? b-a <= epsilon : a-b <= epsilon; }
double rnd(const double x){
return x < 0 ? -rnd(-x) : floor(x + 0.5); }
struct point{
double x, y;
constexpr point(): x(0), y(0){}
point(const double X, const double Y):
x(X), y(Y){}
bool operator==(const point& rhs)const{
return eq(x, rhs.x) && eq(y, rhs.y); }
bool operator<(const point& rhs)const{
return (!eq(x, rhs.x) && x < rhs.x) ||
(eq(x, rhs.x) && !eq(y, rhs.y) && y < rhs.y); } };
ostream& operator<<(ostream& lhs, const point& rhs){
lhs << rhs.x << ' ' << rhs.y;
return lhs; }
point operator-(const point a, const point b){
return point(a.x - b.x, a.y - b.y); }
point operator+(const point a, const point b){
return point(a.x + b.x, a.y + b.y); }
constexpr double sqrt3_pe_2 = 0.866025403784439;
point rotate_60(const point a){
return point(a.x/2 - a.y * sqrt3_pe_2, a.x * sqrt3_pe_2 + a.y/2); }
point rotate_minus_60(const point a){
return point(a.x/2 + a.y * sqrt3_pe_2, -a.x * sqrt3_pe_2 + a.y/2); }
pair<point, point> make_pts(const point a, const point b){
const point r = b-a, v1 = rotate_60(r), v2 = rotate_minus_60(r);
return make_pair(a + v1, a + v2); }
int main(){
ifstream f("triang.in");
ofstream g("triang.out");
int n;
f >> n;
vector<point> puncte;
puncte.reserve(n);
for(int i = 0; i < n; ++i){
double x, y;
f >> x >> y;
puncte.emplace_back(x, y); }
sort(begin(puncte), end(puncte));
int rez = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
if(i != j){
const auto pts = make_pts(puncte[i], puncte[j]);
if(binary_search(begin(puncte), end(puncte), pts.first)){
++rez; }
if(binary_search(begin(puncte), end(puncte), pts.second)){
++rez; } } } }
g << rez/6;
return 0; }