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

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
3
0 0
1 1
2 0
output
1
input
1
1 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值