【CodeForces 618C】Constellation(几何水题)
来源:互联网 发布:Mac的tomcat打不开8080 编辑:程序博客网 时间:2024/05/02 20:48
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
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
题目大意
给你n个点的坐标,要你选3个点构成三角形并且是除这三个点外的所有点都落在这个三角形之外,输出所选择的三个点的序号。
思路
将每个点按x坐标从小到大排列,x坐标相同的情况在根据y坐标从小到大排列(这样可以保证选出来的三个点所构成的三角形尽量小,并且其他点必定在它之外),直接选择第一个和第二个作为前两个序号,接下来枚举剩下的n-2个点判断否满足条件。
代码
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define ll long longusing namespace std;const int maxn=1e5+5;struct proc{ ll list; ll x; ll y;}map[maxn];int n;int cmp(proc a,proc b){ return (a.x<b.x)||(a.x==b.x&&a.y<b.y);}int main(){ while(~scanf("%lld",&n)) { for(int i=1;i<=n;i++) { scanf("%lld %lld",&map[i].x,&map[i].y); map[i].list=i; } sort(map+1,map+1+n,cmp); int m=3; while((map[1].x-map[2].x)*(map[1].y-map[m].y)==(map[1].y-map[2].y)*(map[1].x-map[m].x)) { m++; } printf("%lld %lld %lld\n",map[1].list,map[2].list,map[m].list); } 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 —— 几何
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- Constellation CodeForces
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) 618C Constellation(计算几何+stl)
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) C. Constellation(思维 简单几何)
- cf#Wunder Fund Round 2016 -C - Constellation-计算几何-水题
- Codeforces - Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)C - Constellation(数学练习)
- codeforces 703c(简单几何)
- PreferenceFragmen基本使用
- UVa 679 - Dropping Balls
- IOS UIFont 字体大全
- JAVA--解释器模式(Interpreter)--设计模式二十三
- eclipse设置反编译
- 【CodeForces 618C】Constellation(几何水题)
- Android--Fragment
- iOS地图定位小功能(上)
- eclipse在线安装ivy和ivyde
- android studio生成aar包并在其他工程引用aar包
- 欢迎使用CSDN-markdown编辑器
- jqGrid行编辑配置
- Spring.NET 1.3.2 集成 NHibernate 3.2 - 5 - 事务管理
- Github下载代码与常用命令