Cod sursa(job #1025635)

Utilizator dan.ghitaDan Ghita dan.ghita Data 10 noiembrie 2013 13:14:46
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.68 kb
#include<iostream>
#include<fstream>
#include<functional>
#include<math.h>
#include<set>
#define PI  3.141592653
#define ax imt->first
#define ay imt->second
#define bx jmt->first
#define by jmt->second
using namespace std;
int n, k;
double x, y, a, b;
ifstream f("triang.in");
ofstream g("triang.out");
set< pair<double, double>> m;
set< pair<double, double>>::iterator imt, jmt;
pair<double, double> p;
const double eps = 1e-3;
const double si = sin(PI / 3.0);
const double co = cos(PI / 3.0);
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.insert(make_pair(x, y));
    }

    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--------";
        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);
//        cout<<p.first<<' '<<p.second<<'\n';
        if(m.find(p)!=m.end()) ++k;// cout<<"da\n\n";
//        else cout<<"nu \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);
        //cout<<p.first<<' '<<p.second<<'\n';
        if(m.find(p)!=m.end())++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/3;
    return 0;
}