QBPOINT - Bộ ba điểm thẳng hàng
Tác giả: hieult
Ngôn ngữ: C++
#include <cstdio>
#include <algorithm>
#include <iostream>
//#include <conio.h>
using namespace std;
struct diem{
int x,y;
};
struct vt{
int x,y;
vt(){x = 0;y =0;}
vt(int a,int b){
x = a; y = b;
if(x == 0) y = abs(y);
if(x < 0){
x = -x;
y = -y;
}
}
bool operator < (vt V) const{
return x * V.y < y * V.x;
}
};
int main()
{
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
int test,n,so;
long long kq,run;
diem A[2222];
vt V[2222];
// scanf("%d",&test);
//for(int itest = 0;itest<test;itest++){
scanf("%d",&n);
for(int i = 0;i<n;i++)
scanf("%d %d",&A[i].x,&A[i].y);
kq = 0; so = 0;
for(int i = 0;i<n-1;i++){
run = 0;
for(int j = i+1;j<n;j++)
V[j-i-1] = vt(A[j].x-A[i].x,A[j].y-A[i].y);
sort(V, V + n - i - 1);
for(int j = 0; j<n-i-2;j++){
if(!(V[j] < V[j + 1])){
run++;
}
else{
run = 0;
}
kq+=run;
}
// printf("%d %d\n",i,kq);
// printf("1");
}
printf("%lld",kq);
//}
//getch();
}