您的位置:首页 > 其它

Codeforces 552D. Vanya and Triangles【向量判三点共线】

2016-04-24 10:10 399 查看
D. Vanya and Triangles

time limit per test
4 seconds

memory limit per test
512 megabytes

input
standard input

output
standard output

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.

Input

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.

Output

In the first line print an integer — the number of triangles with the non-zero area among the painted points.

Examples

input
4
0 0
1 1
2 0
2 2


output
3


input
30 01 12 0


output
1


input
11 1


output
0


Note

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.

题意,给出n 个点,问最多可以构成多少个三角形,判三点是否共线。向量a (x1 , y1 ) 向量b(x2 , y2 ),平行 x1*y2-x2*y1==0 ,垂直 x1*x2+y1*y2==0
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define maxn 2020using namespace std;
int x[maxn],y[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;++i)
scanf("%d%d",&x[i],&y[i]);
int cnt=0;
for(int i=1;i<=n;++i)
{
for(int j=i+1;j<=n;++j)
{
for(int k=j+1;k<=n;++k)
{
if((x[j]-x[i])*(y[k]-y[i])-(y[j]-y[i])*(x[k]-x[i])!=0)
cnt++;
}
}
}
printf("%d\n",cnt);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: