CodeForces 552D-Vanya and Triangles【计算整数三点能否组成三角形】
来源:互联网 发布:同花顺软件怎么使用 编辑:程序博客网 时间:2024/05/17 01:31
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.
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.
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
40 01 12 02 2
3
30 01 12 0
1
11 1
0
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 552D-Vanya and Triangles【计算整数三点能否组成三角形】
- 552D Vanya and Triangles (求任意三点组成的三角形个数)
- Codeforces 552D Vanya and Triangles
- CodeForces 552D Vanya and Triangles
- 【25.33%】【codeforces 552D】Vanya and Triangles
- CodeForces - 552D Vanya and Triangles (数学几何求三角形个数)水
- CodeForces 552D — Vanya and Triangles 暴力枚举
- Codeforces 552D. Vanya and Triangles【向量判三点共线】
- Codeforces 552D Vanya and Triangles【暴力枚举+思维】
- Codeforces Round #308 (Div. 2) D. Vanya and Triangles (判断三角形数量)
- cf#308-D - Vanya and Triangles-求平面点集中三角形个数-枚举-n^2logn
- codeforces #308 D.Vanya and Triangles(枚举+斜率分块)
- D. Vanya and Triangles(Codeforces Round #308 (Div. 2))
- Codeforces Round #308 (Div. 2) D. Vanya and Triangles
- Codeforces Round #308 (Div. 2) D Vanya and Triangles
- Codeforce 552D Vanya and Triangles(暴力枚举)
- #308 (div.2) D. Vanya and Triangles
- cf #308 D. Vanya and Triangles (几何)
- 构造、析构、对象与继承
- Codeforces 662D International Olympiad【贪心】
- C# Substring 和 String.join 0010
- JDBC连接数据库
- `## 八皇后的判断 ###
- CodeForces 552D-Vanya and Triangles【计算整数三点能否组成三角形】
- 《C#入门经典v6》读书笔记5 WCF&WWF
- 获取jquery打分插件rateit 的分值
- Encoding
- 如何有效的使用谷歌搜索引擎(How to Use Google Search More Effectively)
- EditText中一些属性的用法
- Qt设计用户界面的三种方法
- 2016sdau课程练习专题二 1011
- com.google.android.xts.devicepolicy.DeviceOwnerTest#testFactoryResetProtection fail