java n个点 凸多边形_hrbustoj 1291 点在凸多边形内

分析:因为是凸多边形,所以只要对每条边求一下叉积即可.

设有向量P和Q则它们的叉积PXQ有以下性质:

1.PXQ>0  时,则P在Q的顺时针方向;

2.PXQ<0  时,则P在Q的逆时针方向;

3.PXQ=0  时,则P和Q共线,可能同向,也可能是反向;

#include

#include

#include

#include

#include

#include

#include

using namespace std;

const int maxn=100000;

struct point{

int x,y;

void read(){

cin>>x>>y;

}

}rt,f[maxn];

double cross(point p0,point p1,point p2){///叉积

return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);

}

int main(){

int n;

while(cin>>n){

rt.read();

for(int i=0;i

f[i].read();

f[n]=f[0];

bool ok=true;

for(int i=0;i

if(cross(f[i],f[i+1],rt)<0){///在边的外部

ok=false; break;

}

if(ok) puts("Yes");

else puts("No");

}

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值