CodeForces - 618C —— Constellation —— 几何
来源:互联网 发布:做淘宝真的比上班累吗 编辑:程序博客网 时间:2024/05/17 20:01
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.
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.
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.
30 11 01 1
1 2 3
50 00 22 02 21 1
1 3 5
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).
题意:
给你一个数n;
然后给你n组坐标(x,y)。让你挑出三个点,使得着三个点组成的三角形内没有其余的点。
任取其中一组答案即可。
思路:
先将所有坐标放入同一个结构体数组中。
然后依据y坐标相同时,按小x坐标从小到大排序;
x坐标相同时,按y坐标从小到大排序
然后前两个数组中元素连线之间肯定不会再有其它的点,所以可以从第三个开始找,找到一个点当这三个点形成的两条边不平行时,break;
判断三坐标形成的两条线段是否平行的方法,查阅了一下叫做叉积。结论记住就行了
#include <iostream>#include <cstdio>#include <cstdlib>#include <string>#include <cmath>#include <algorithm>#include <cstring>#include <map>#include <set>#include <sstream>#include <queue>#include <stack>#define INF 0x3f3f3f3f#define mem(a,b) memset(a,b,sizeof(a));#define For(a,b) for(int i = a;i<b;i++)#define ll long long#define MAX_N 100010using namespace std;struct stri{ ll x; ll y; int pos;}s[MAX_N];bool cmp(stri a,stri b){ if(a.x == b.x) return a.y < b.y; else return a.x < b.x;}bool check(stri p){ if((s[0].x - p.x) * (s[1].y - p.y) != (s[0].y - p.y) * (s[1].x - p.x)) return true; return false;}int main(){ int n; while(~scanf("%d",&n)) { for(int i = 0; i<n; i++) { ll a,b; scanf("%lld %lld",&a,&b); s[i].pos = i+1; s[i].x = a; s[i].y = b; } if(n == 3) { cout<<"1 2 3"<<endl; continue; } sort(s,s + n,cmp); for(int i = 2; i<n; i++) { if(check(s[i])) { printf("%d %d %d\n",s[0].pos,s[1].pos,s[i].pos); break; } } } return 0;}
- CodeForces - 618C —— Constellation —— 几何
- 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(几何水题)
- Constellation CodeForces
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) 618C Constellation(计算几何+stl)
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- cf#Wunder Fund Round 2016 -C - Constellation-计算几何-水题
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- Codeforces Beta Round #13 D —— Triangles 计算几何
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) C. Constellation(思维 简单几何)
- 高等几何——射影几何整理
- 1025. PAT Ranking (25)
- Apache与Nginx的优缺点比较
- 单例模式
- 浅析spring中创建的对象如何保证不被回收
- 监听数据库中的缓存配置以更新内存中的缓存数据
- CodeForces - 618C —— Constellation —— 几何
- 嵌入式:节省内存的软件设计技巧
- 升级到SQL Server 2012-2014时一些需要考虑的事项
- 【BZOJ 4539】[Hnoi2016]树 倍增lca+主席树
- Ubuntu 网络管理命令
- 由浅入深探究mysql索引结构原理、性能分析与优化
- 关于奇异值以及奇异值分解SVD的思考
- 二维灰度地形图山脊线自动提取方法整理(PPA)
- 解决Spring事务不回滚