Codeforces 618C(计算几何)
2 seconds
256 megabytes
standard input
standard output
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.
3
0 1
1 0
1 1
1 2 3
5
0 0
0 2
2 0
2 2
1 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).
题意:给定一些点,选三个点构成三角形,别的点都在三角形外。
做法:按x为关键字,y为次关键字将所有的点排序,选定1,2两个点,枚举第3个点判断是否能构成三角形。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
struct ss
{
long long x,y,id;
};
inline bool cmp(ss a,ss b)
{
return (a.x<b.x||a.x==b.x&&a.y<b.y);
}
bool check(ss a,ss b,ss c)
{
return 1ll*(c.x-a.x)*(b.y-a.y)-1ll*(c.y-a.y)*(b.x-a.x)!=;
}
int n;
ss a[];
int main()
{
scanf("%d",&n);
int i;
for (i=;i<=n;i++)
scanf("%lld%lld",&a[i].x,&a[i].y),a[i].id=i;
sort(a+,a+n+,cmp);
//for (i=1;i<=n;i++)
// printf("%d %d\n",a[i].x,a[i].y);
for (i=;i<=n;i++)
if (check(a[],a[],a[i]))
{
printf("%lld %lld %lld\n",a[].id,a[].id,a[i].id);
return ;
}
return ;
}
Codeforces 618C(计算几何)的更多相关文章
- 【CodeForces 618C】Constellation
题 Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars n ...
- CodeForces 618C CodeForces 618C
第一反应是在凸包上随便找一条边,然后找剩下n-2个点里面距离这条边最短的一个点,这三点就构成了符合要求的三角形..然而..精度被卡死. 换种思路,随便找两个点P1,P2,找剩下n-2个点中哪一个点与P ...
- Codeforces Gym100543B 计算几何 凸包 线段树 二分/三分 卡常
原文链接https://www.cnblogs.com/zhouzhendong/p/CF-Gym100543B.html 题目传送门 - CF-Gym100543B 题意 给定一个折线图,对于每一条 ...
- BUPT2017 wintertraining(15) #1 题解
拖了一周才完成的题解,抛出一个可爱的表情 (っ'-')╮ =͟͟͞͞❤️.对我来说E.F比较难,都是线段树的题,有点久没写了. A - Infinite Sequence CodeForces - 6 ...
- Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何
C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...
- Codeforces 749B:Parallelogram is Back(计算几何)
http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...
- Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何
A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends(思维+计算几何?)
传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ ...
- Codeforces 528E Triangles 3000 - 计算几何
题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah ...
随机推荐
- JAVA设计模式--Strategy
策略模式就是说当我进行比较大小的时候定义一个策略的比较器Comparator,然后由具体的比较策略来决定用什么量来比较大小.
- webuploader上传工具
http://fex.baidu.com/webuploader/getting-started.html#显示用户选择 Html部分 首先准备dom结构,包含存放文件信息的容器.选择按钮和上传按钮三 ...
- JDO
JDO 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! JDO(Java Data Object )是Java对象持久化的新的规范,也是一个用于存取某种数据仓库中的对象 ...
- sqlit3事务
事务定义了一组SQL命令的边界,这组命令或者作为一个整体被全部执行,或者都不执行.事务的典型实例是转帐. 事务的范围 事务由3个命令控制:BEGIN.COMMIT和ROLLBACK.BEGIN开始一个 ...
- vs code 插件list
vs code 插件list
- cocos creator 小记
一个游戏场景有若干个节点组成,这些包括渲染节点,UI节点. 这里弱化了Layer层的概念. 一个游戏由若干个场景组件. 每个节点由若干个组件和若干子节点组成. 例如UI节点中的 按钮节点.子节点有 ...
- 在CNN网络中roi从原图映射到feature map中的计算方法
在使用fast rcnn以及faster rcnn做检测任务的时候,涉及到从图像的roi区域到feature map中roi的映射,然后再进行roi_pooling之类的操作.比如图像的大小是(600 ...
- python数组中数据位置交换 -- IndexError: list assignment index out of range
代码: t = [-10,-3,-100,-1000,-239,1] # 交换 -10和1的位置 t[5], t[t[5]-1] = t[t[5]-1], t[5] 报错: IndexError: l ...
- js多维数组扁平化
数组扁平化,就是将多维数组碾平为一维数组,方便使用. 一:例如,一个二维数组 var arr = ['a', ['b', 2], ['c', 3, 'x']],将其扁平化: 1. 通过 apply ...
- Canal使用报错解决办法
1. [destination = test_cancal , address = /127.0.0.1:3306 , EventParser] WARN c.a.o.s.a.i.setl.zooke ...