您的位置:首页 > 其它

cf#Wunder Fund Round 2016 -C - Constellation-计算几何-水题

2016-01-30 11:53 337 查看
http://codeforces.com/contest/618/problem/C

给你n个点,保证 不会所有点在一条线上

让你找出一个三角形。使得三角形内部+边上没有任何别的点

直接按坐标排个序,for遍历连续的三个点作为三角形(必然不会有别的点在此三角形之内)

然后判断是否会面积为零,不会即合法,会则跳过

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include<stack>
using namespace std;

const __int64 INF=9223372036854775807;
struct POINT
{
int id;
double x;
double y;
POINT(double a=0, double b=0) { x=a; y=b;}
};
POINT tm[100000+5];
double multiply(POINT sp,POINT ep,POINT op)
{
return((sp.x-op.x)*(ep.y-op.y) - (ep.x-op.x)*(sp.y-op.y));
}
int cmp(POINT a,POINT b)
{
if (a.x!=b.x)
return a.x<b.x;
else
return a.y<b.y;
}
int main()
{
int i,j;
int n;
cin>>n;
for (i=1;i<=n;i++)
{
scanf("%lf%lf",&tm[i].x,&tm[i].y);
tm[i].id=i;
}
sort(tm+1,tm+1+n,cmp);
int flag=0;
for (i=1;i<=n-2;i++)
{
double cs=multiply(tm[i],tm[i+1],tm[i+2])/2;
if (fabs(cs)<1e-6) continue;
printf("%d %d %d\n",tm[i].id,tm[i+1].id,tm[i+2].id);break;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: