Cod sursa(job #803308)

Utilizator wzrdwzrd tst wzrd Data 27 octombrie 2012 12:55:32
Problema Triang Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <cmath>
#include <set>
#define DN 1505
#define x first
#define y second
using namespace std;

typedef pair<double,double> per;

int n,rez;
per p[DN];
double r32=sqrt(3.0)/2;
set<per> s1;
set<per,greater<per> > s2;

inline int cauta(per p) {
    set<per>::iterator is=s1.lower_bound(p);
    if(is!=s1.end() && fabs(p.x-is->x)<1e-5 && fabs(p.y-is->y)<1e-5)return 1;

    set<per,greater<per> >::iterator is2=s2.lower_bound(p);
    if(is2!=s2.end() && fabs(p.x-is2->x)<1e-5 && fabs(p.y-is2->y)<1e-5)return 1;
    return 0;
}

int main()
{
    ifstream f("triang.in");
    ofstream g("triang.out");
    f>>n;
    for(int i=0; i<n; ++i) {
        f>>p[i].x>>p[i].y;
        s1.insert(p[i]);
        s2.insert(p[i]);
    }
    for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j) {
        per n;
        n.x=(p[i].x+p[j].x)*0.5-r32*(p[j].y-p[i].y);
        n.y=(p[i].y+p[j].y)*0.5+r32*(p[j].x-p[i].x);

        rez+=cauta(n);

        n.x=(p[i].x+p[j].x)*0.5+r32*(p[j].y-p[i].y);
        n.y=(p[i].y+p[j].y)*0.5-r32*(p[j].x-p[i].x);
        rez+=cauta(n);
    }
    g<<rez/3;
    return 0;
}