Cod sursa(job #803300)

Utilizator wzrdwzrd tst wzrd Data 27 octombrie 2012 12:45:17
Problema Triang Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <set>
#define DN 2005
using namespace std;

typedef pair<double,double> per;

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

double fabs(double x) {
    if(x<0) return -x;
    return x;
}

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

    set<per,greater<per> >::iterator is2=s2.lower_bound(make_pair(x,y));
    if(is2!=s2.end() && fabs(x-is2->first)<1e-5 && fabs(y-is2->second)<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>>x[i]>>y[i];
        s1.insert(make_pair(x[i],y[i]));
        s2.insert(make_pair(x[i],y[i]));
    }
    for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j) {
        double nx=(x[i]+x[j])*0.5-r32*(y[j]-y[i]);
        double ny=(y[i]+y[j])*0.5+r32*(x[j]-x[i]);

        rez+=cauta(nx,ny);

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