CodeForces 618 C. Constellation(计算几何)
来源:互联网 发布:手机点击软件快速 编辑:程序博客网 时间:2024/05/17 13:10
Description
给出n个整点的坐标,要求找到三个点使得这三个点可以组成一个三角形且其余所有点都严格在这个三角形外,保证解存在
Input
第一行为一整数n表整点个数,之后n行每行两个整数xi和yi表示该整点坐标(3<=n<=100000,-10^9<=xi,yi<=10^9)
Output
输出满足条件的三个点的编号
Sample Input
5
0 0
0 2
2 0
2 2
1 1
Sample Output
1 3 5
Solution
简单计算几何,给点排序,固定排序之后的前两个点去枚举第三个点检查是否能够构成三角形即可
Code
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;#define maxn 111111typedef long long ll;struct node{ ll x,y; int id;}p[maxn];int n;int cmp(node a,node b){ if(a.x!=b.x)return a.x<b.x; return a.y<b.y;}bool check(node a,node b,node c){ return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x)!=0;}int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++)scanf("%I64d%I64d",&p[i].x,&p[i].y),p[i].id=i; sort(p+1,p+n+1,cmp); for(int i=3;i<=n;i++) if(check(p[1],p[2],p[i])) { printf("%d %d %d\n",p[1].id,p[2].id,p[i].id); break; } } return 0;}
0 0
- 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 - 618C —— Constellation —— 几何
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- Wunder Fund Round 2016 C. Constellation(贪心+计算几何)
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) 618C Constellation(计算几何+stl)
- cf#Wunder Fund Round 2016 -C - Constellation-计算几何-水题
- CodeForces 1C(计算几何)
- codeforces 1C 计算几何
- Constellation CodeForces
- Codeforces 703C Chris and Road(计算几何)
- MySQL用户授权
- Google Guava官方教程(中文版 转载)
- 虚拟机Linux下安装bro过程
- Linux用rename给文件批量加后缀
- json-c库例子
- CodeForces 618 C. Constellation(计算几何)
- TSP问题 动态规划实现
- cocos2dx实现经典飞机大战
- 谈乔布斯艺术家情怀的魅力
- 为什么用String.format?,什么时候用String.format?
- Lua的math函数库
- 20160209.CCPP体系详解(0019天)
- 约会(并查集)
- 两个堆栈m和n(m<n)模拟一个队列,容量为m+m