Cod sursa(job #1020356)

Utilizator ELHoriaHoria Cretescu ELHoria Data 1 noiembrie 2013 22:52:30
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.56 kb
#include <fstream>
#include <math.h>
#include <algorithm>
#include <functional>
#include <vector>
#define pdd pair<double,double>
#define PI  3.141592653
  
#define x first
#define y second
  
using namespace std;
 
ifstream cin("test.in");
ofstream cout("test.out");
  
const double eps = 1e-3;
const double s60 = sin(PI / 3.0);  
const double c60 = cos(PI / 3.0);
const int nmax = 1502;
int n;
pdd v[nmax];
  
inline pdd getPoint(pdd a,pdd b) {
    return make_pair( a.x + c60*(b.x - a.x) - s60*(b.y-a.y),a.y + s60*(b.x - a.x) + c60*(b.y - a.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 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<<11;step > 0;step >>= 1) {
        if(pos + step < n && comp(v[pos + step],p) < 1) {
              pos += step;
         }
    }
      
    return comp(p,v[pos]) == 0;
}
  
inline int solve() {
    int ret = 0;
    sort(v,v + n);
    for(int i = 0;i < n;i++) {
        for(int j = i + 1;j < n;j++) {
            ret += search(getPoint(v[i],v[j]));
            ret += search(getPoint(v[j],v[i]));
        }
    }
    ret /= 3;
    return ret;
}
  
int main()
{
    readData();
    cout<<solve()<<"\n";
    return 0;
}