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
output
input
output
input
output
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
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;
}
相关文章推荐
- 成长点滴
- 视频码流
- 栈和队列的有关操作
- 南洋理工之导弹拦截(79)
- java文件操作工具类
- ZOJ-3939-The Lucky Week【13th浙江省赛】【找规律】
- 第四次C++作业
- android仿win8
- Labview之ActiceX学习
- 把本地文件上传到github
- poj 1695(三维dp)
- android文件存储
- Android 5.X 新特性
- 线程
- 推荐一个linux下的web压力测试工具神器webbench
- Citrix Receive问题解决2
- 庖丁解牛之仿《闪传》实现文件传输(下)
- hdu4722 Good Numbers(数位dp)
- Oracle之深入浅出(二)--SQL原理、解释计划与执行计划
- 微软面试题:五个囚犯抓绿豆