Codeforces--618C--Constellation(数学几何)(技巧)
来源:互联网 发布:java学会了能做什么 编辑:程序博客网 时间:2024/05/17 06:13
Description
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 ≤ n ≤ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Sample Input
30 11 01 1
1 2 3
50 00 22 02 21 1
1 3 5
Hint
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Source
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
题意:给出n个点的坐标,然后找一个三角形,这个三角形中不含其他的点,输出可能有多种情况,输出一种就好
思路:将所有的点排序,按照x升序排列,x相同的按照y升序,然后取最靠边的两个点,作为三角形的其中两个点,然后取这两个点后面的点,判断是否可以构成三角形,因为已经排过序,所以我们使用第一个点的时候不会出现三角形中间夹一个点的情况,即使后边会出现舍点的情况,但这也是因为这个点跟前边的两个点共线,形成三角形是不允许三点共线的,因此排序之后就是枚举,点的坐标范围有点大,所以__int64最好,要不然就会wa到12组,不要问我为什么
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{__int64 x,y;int num;}p[100000+10];bool cmp(node s1,node s2){if(s1.x==s2.x)return s1.y<s2.y;return s1.x<s2.x;}bool judge(node s){if((p[1].x-s.x)*(p[2].y-s.y)==(p[1].y-s.y)*(p[2].x-s.x))return false;return true;}int main(){int n;while(scanf("%d",&n)!=EOF){for(int i=1;i<=n;i++){scanf("%I64d%I64d",&p[i].x,&p[i].y);p[i].num=i;}sort(p+1,p+1+n,cmp);if(n==3)printf("1 2 3\n");else{for(int i=3;i<=n;i++){if(judge(p[i])){printf("%d %d %d\n",p[1].num,p[2].num,p[i].num);break;}}}}return 0;}
- Codeforces--618C--Constellation(数学几何)(技巧)
- CodeForces 618 C. Constellation(计算几何)
- 【CodeForces 618C】Constellation(几何水题)
- codeforces 618C. Constellation
- CodeForces 618C Constellation
- Codeforces 618C Constellation
- Codeforces 618C Constellation
- CodeForces 618C 、Constellation
- Codeforces 618C Constellation(简单几何题—叉积)
- CodeForces - 618C —— Constellation —— 几何
- Codeforces - Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)C - Constellation(数学练习)
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- CodeForces - 659D Bicycle Race (数学几何&技巧转换)
- 【Codeforces】-445C-DZY Loves Physics(几何,数学)
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) C. Constellation(思维 简单几何)
- CodeForces - 621B Wet Shark and Bishops (数学几何&技巧)
- Constellation CodeForces
- javascript之函数
- 【Linux进程间通信】 - 消息队列
- fckeditor上传文件按日期存放及重命名方法
- java 内存模型综述
- 贪心专题总结
- Codeforces--618C--Constellation(数学几何)(技巧)
- Vim学习笔记(二) - linux与windows之间文件乱码问题
- android 如何进行单元测试
- java HASHMAP 实现原理
- 矩形相交的面积
- Android记录软件每天第一次打开
- 比较出名的几个树莓派论坛
- 设计模式之单例模式
- C++中的const常见的用法总结