CodeForces 552D-Vanya and Triangles【计算整数三点能否组成三角形】
2016-04-21 20:14
459 查看
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.
解题思路:
就是给出一些点看能找出多少三角形。因为是整数点,所以很好判。
暴力可以过。
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.
解题思路:
就是给出一些点看能找出多少三角形。因为是整数点,所以很好判。
暴力可以过。
#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; }
相关文章推荐
- Codeforces 527B. Error Correct System【字符串】
- 学习进度表
- PerformanceCounter 基本介绍以及示例方法
- 第八周、第九周学习总结
- 第八周、第九周学习总结
- 第八周----补
- java怎么循环遍历ArrayList
- csv转Libsvm格式
- 实验二 作业调度模拟程序
- [翻译]现代java开发指南 第一部分
- com.google.android.xts.devicepolicy.DeviceOwnerTest#testFactoryResetProtection fail
- Android Studio、Java安装及环境变量配置
- Android按照拼音排序获取联系人并根据拼音首字母获取联系人
- Encoding
- Qt设计用户界面的三种方法
- 【BZOJ2152】聪明的可可 树的点分治
- HDU 4920 Matrix multiplication(矩阵相乘)
- 团队开发个人总结03
- 抽取、转换和装载介绍(八)实时的意义(待续)
- 冲刺阶段第四天