CodeForces 552D-Vanya and Triangles【计算整数三点能否组成三角形】

来源:互联网 发布:同花顺软件怎么使用 编辑:程序博客网 时间:2024/05/17 01:31
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
40 01 12 02 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.

解题思路:

就是给出一些点看能找出多少三角形。因为是整数点,所以很好判。

暴力可以过。

#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;}


1 0