Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
4 0 0 1 1 2 0 2 2
3
3 0 0 1 1 2 0
1
1 1 1
0
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
解题思路:
就是给出一些点看能找出多少三角形。因为是整数点,所以很好判。
暴力可以过。
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
const double eps=1e-8;
struct node
{
int x,y;
}num[1000005];
/*bool cc(node p1,node p2,node p3)
{
if(p2.x>=min(p1.x,p3.x)&&p2.x<=max(p1.x,p3.x)
&&p2.y>=min(p1.y,p3.y)&&p2.y<=max(p1.y,p3.y))
{
return fabs((p2.x-p1.x)*1.0*(p3.y-p1.y)-(p3.x-p1.x)*1.0*(p2.y-p1.y))<=eps;
}
}*/
bool cc(int i,int j,int k)
{
if((num[i].y-num[j].y)*(num[k].x-num[i].x)!=(num[k].y-num[i].y)*(num[i].x-num[j].x))
return 1;
return 0;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int i,j,k;
for(i=1;i<=n;i++)
{
scanf("%d%d",&num[i].x,&num[i].y);
}
if(n<=2)
{
printf("0\n");
continue;
}
int ans=0;
for(i=1;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
for(k=j+1;k<=n;k++)
{
if(cc(i,j,k)==1)
ans++;
}
}
}
printf("%d\n",ans);
}
return 0;
}