hrbustoj 1291 点在凸多边形内

题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1291

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

设有向量则它们的叉积X有以下性质:

1.X>0  时,则PQ的顺时针方向;

2.X<0  时,则PQ的逆时针方向;

3.X=0  时,则PQ共线,可能同向,也可能是反向;

 

#include<iostream>

#include<string>

#include<cstring>

#include<algorithm>

#include<cstdio>

#include<cmath>

#include<iomanip>



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<n;++i)

            f[i].read();

        f[n]=f[0];

        bool ok=true;

        for(int i=0;i<n;++i)

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

                ok=false; break;

            }

        if(ok) puts("Yes");

        else   puts("No");

    }

    return 0;

}














 

 

你可能感兴趣的:(OJ)