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;
}
给你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;
}
相关文章推荐
- 关于JDK8跑项目会抛出的type mismatch between read and write
- Scalaz(26)- Lens: 函数式不可变对象数据操作方式
- 【同行说技术】教你玩转iOS的5篇技术干货
- 如何改掉坏习惯?
- 学习计划
- ADB server didn't ACK 问题解决办法汇总
- Linux信号—可靠信号与不可靠信号实践
- springmvc返回值、数据写到页面、表单提交、ajax、重定向
- Scalaz(26)- Lens: 函数式不可变对象数据操作方式
- intellij idea中刷新gradle无效
- java8 list match
- 国行的Moto 360 语音口令 ,Android Wear 的口令,语音命令,语音控制
- 关于jquery中resize用法
- Android之SharedPreferences详解与原理分析
- Linux下卸载keepalived
- Kinect for Windows中文网站
- 统计文件中单词的个数---Shell及python版
- Java模拟post实现图片上传
- cf#Wunder Fund Round 2016 -B- Guess the Permutation-构造-乱搞
- 进制转换