Cod sursa(job #1025679)

Utilizator dan.ghitaDan Ghita dan.ghita Data 10 noiembrie 2013 14:04:37
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.06 kb
#include<iostream>
#include<fstream>
#include<functional>
#include<math.h>
#include<map>
#define ax imt->first.first
#define ay imt->first.second
#define bx jmt->first.first
#define by jmt->first.second
using namespace std;
int n, k;
double x, y, a, b;
ifstream f("triang.in");
ofstream g("triang.out");
map< pair<double, double>, int> m;
map< pair<double, double>, int>::iterator imt, jmt, lb, ub;
pair<double, double> p;
const double eps = 0.01;
double si=0.8660254, co=0.5;
int main()
{
    f>>n;
    for(int i=0; i<n; ++i) {
        f>>x>>y;
        x = round(x * 10000.0) / 10000.0;
        y = round(y * 10000.0) / 10000.0;
        m[make_pair(x, y)]=1;
    }

    for(imt=m.begin(); imt!=m.end(); ++imt){
            jmt=imt;++jmt;
    for(; jmt!=m.end(); ++jmt){
//        cout<<"puncte:\n"<<ax<<' '<<ay<<'\n';
//        cout<<bx<<' '<<by<<"\n--------\n";
        a=ax+co*(bx-ax)-si*(by-ay);
        b=ay+si*(bx-ax)+co*(by-ay);
        a=round(a*10000.0)/10000.0;
        b=round(b*10000.0)/10000.0;
        p=make_pair(a,b);
        lb=m.lower_bound(p);
        ub=m.upper_bound(p);
//        cout<<p.first<<' '<<p.second<<'\n';
if(((fabs(lb->first.first-p.first)<eps) && (fabs(lb->first.second-p.second)<eps))||((fabs(ub->first.first-p.first)<eps) && (fabs(ub->first.second-p.second)<eps)))
            ++k;//, cout<<"da\n\n";
//        else cout<<"nu \n\n";

        a=ax+(bx-ax)*co+(by-ay)*si;
        b=ay-(bx-ax)*si+(by-ay)*co;
        a = round(a * 10000.0) / 10000.0;
        b = round(b * 10000.0) / 10000.0;
        p=make_pair(a, b);
//        cout<<p.first<<' '<<p.second<<'\n';
        lb=m.lower_bound(p);
        ub=m.upper_bound(p);
if(((fabs(lb->first.first-p.first)<eps) && (fabs(lb->first.second-p.second)<eps))||((fabs(ub->first.first-p.first)<eps) && (fabs(ub->first.second-p.second)<eps)))
           ++k;//, cout<<"da\n--------\n";
//        else cout<<"nu \n--------\n";
    }
    }

//    cout<<'\n';
//    for(imt=m.begin(); imt!=m.end(); ++imt)
//    cout<<ax<<' '<<ay<<'\n';
    g<<k/3; cout<<k;
    return 0;
}