Cod sursa(job #1020346)

Utilizator ELHoriaHoria Cretescu ELHoria Data 1 noiembrie 2013 22:36:35
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.6 kb
#include <fstream>
#include <math.h>
#include <algorithm>
#include <functional>
#include <vector>
#define pdd pair<double,double>
#define M_PI  3.141592653
 
#define x first
#define y second
 
using namespace std;

ifstream cin("triang.in");
ofstream cout("triang.out");
 
const double eps = 1e-3;
const double s60 = sin(M_PI / 3.0);   
const double c60 = cos(M_PI / 3.0);
const int nmax = 1502;
int n;
pdd v[nmax];
 
inline pdd getPoints(pdd a,pdd b) {
      return  make_pair(c60 * (a.x - b.x) - s60 * (a.y - b.y) + b.x,s60 * (a.x - b.x) + c60 * (a.y - b.y) + b.y);
}

inline int cmp(const double a,const double b) {
    if(a + eps < b) return -1;
    if(b + eps < a) return 1;
    return 0;
}
 
 
inline int comp(const pdd &a,const pdd &b) {
	if(cmp(a.x,b.x) == 0) {
		return cmp(a.y,b.y);
	}
	return cmp(a.x,b.x);
}

inline bool cc(const pdd &a,const pdd &b) {
	return comp(a,b) == -1;
}
 
inline void readData() {
    cin>>n;
    for(int i = 0;i < n;i++) {
		cin>>v[i].x>>v[i].y;
    }
}
 
inline bool search(pdd p) {
    int pos = 0;
    for(int step = 1<<12;step > 0;step >>= 1) {
        if(pos + step < n && comp(p,v[pos + step]) < 1) {
               pos += step;
         }
    }
     
    return comp(p,v[pos]) == 0;
}
 
inline int solve() {
    int ret = 0;
    sort(v,v + n,cc);
    for(int i = 0;i < n;i++) {
        for(int j = i + 1;j < n;j++) {
            ret += search(getPoints(v[i],v[j]));
			ret += search(getPoints(v[j],v[i]));
        }
    }
    return ret;
}
 
int main()
{
    readData();
    cout<<solve()<<"\n";
    return 0;
}