PRAVO - Tam giác vuông

Tác giả: hieult

Ngôn ngữ: C++

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
//#include<conio.h>
#define maxn 1502
#define oo 1111111111
#define base 100000000
#define TR(c, it) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
long double const PI= acos((long double)(-1));
long double const ep = 0.000000000001;
using namespace std;

typedef pair<int, int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;
typedef long double ld;

void OPEN(){
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout); 
}

struct diem{
     long long x,y;
};

struct vec_tor{
     long long x,y;
     long double goc;
     vec_tor(){};
     vec_tor(diem D1,diem D2){
           x = D2.x-D1.x;
           y = D2.y-D1.y;
           if(y<0){
                x = -x;
                y = -y;
           }
           if(y==0) x>0?x:-x;
           goc = atan2((ld)y,(ld)x);
     }
     bool operator <(vec_tor T)const{
           return (x*T.y>y*T.x);// && x * T.x >= 0 && y * T.y >= 0);
     }
     bool operator ==(vec_tor T)const{
           return ( x*T.y == y*T.x && x * T.x >= 0 && y * T.y >= 0);
     }
     int vuonggoc(vec_tor T) const{
           if (x*T.x==-y*T.y) return 0;
           if(x * T.x + y * T.y > 0) return 1;
           return -1;
     }
};

diem A[1511];
vec_tor  V[3011];
long long KQ = 0;
int n;

int main(){
     //OPEN();
     scanf("%d",&n);
     for(int i = 0;i<n;i++)
           scanf("%lld %lld",&A[i].x,&A[i].y);
     for(int i = 0;i<n;i++){ 
           int t = 0; 
           for(int j = 0;j<n;j++){
                 if(i!=j)
                      V[t++] = vec_tor(A[i],A[j]);
           }
           sort(V,V+t);
           int u=0,run = 0;
           for(int j = 0;j<t;j++){
                 if(j>0 && V[j]==V[j-1]){
                      KQ+=run;
                      continue;
                 } 
                 while(V[j].vuonggoc(V[u]) == 1 && u<t) u++;
                 run = 0;
                 while(V[j].vuonggoc(V[u]) == 0 && u<t){                 
                      u++;
                      run++;
                      KQ++;
                 }
           } 
     }
     printf("%lld",KQ);
     //getch();
}



Download