sgu124

124. Broken line

time limit per test: 0.5 sec.
memory limit per test: 4096 KB

There is a closed broken line on a plane with sides parallel to coordinate axes, without self-crossings and self-contacts. The broken line consists of K segments. You have to determine, whether a given point with coordinates (X0,Y0) is inside this closed broken line, outside or belongs to the broken line.

Input

The first line contains integer K (4 Ј K Ј 10000) - the number of broken line segments. Each of the following N lines contains coordinates of the beginning and end points of the segments (4 integer xi1,yi1,xi2,yi2all numbers in a range from -10000 up to 10000 inclusive). Number separate by a space. The segments are given in random order. Last line contains 2 integers X0 and Y0 - the coordinates of the given point delimited by a space. (Numbers X0, Y0 in a range from -10000 up to 10000 inclusive).

Output

The first line should contain:

INSIDE - if the point is inside closed broken line,

OUTSIDE - if the point is outside,

BORDER - if the point belongs to broken line.

Sample Input

4
0 0 0 3
3 3 3 0
0 3 3 3
3 0 0 0
2 2

Sample Output

INSIDE

Author: Alex Y. Suslov, Sergey V. Mironov
Resource: 5th Southern Subregional Contest. Saratov 2002
Date: 2002-10-10


题目大意,给你一个多边形以及一个点(保证多边形每条边都平行于坐标轴),判断该点是否在多边形内部


方法:可以考虑从该点做一条射线,判断与每一条边是否相交即可。

如果相交次数不是2的倍数,那么说明该点在多边形内部,否则在多边形外部。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

struct point{
    double x,y;
};
struct edge{
    point a,b;
}e[10101];
int n;
point p1;
int main(){
    //init
    std::ios::sync_with_stdio(false);
    cin >> n;
    for (int i=1;i<=n;++i){
	cin >> e[i].a.x >> e[i].a.y
	    >> e[i].b.x >> e[i].b.y;
	if (e[i].a.x==e[i].b.x && 
	    e[i].a.y>e[i].b.y) swap(e[i].a.y,e[i].b.y);
	if (e[i].a.y==e[i].b.y &&
	    e[i].a.x>e[i].b.x) swap(e[i].a.x,e[i].b.x);
    }
    cin >> p1.x >> p1.y;
    //solve
    for (int i=1;i<=n;++i){
	if (e[i].a.x==e[i].b.x && e[i].a.x==p1.x &&
	    e[i].a.y<=p1.y && e[i].b.y>=p1.y){
	    cout << "BORDER" << endl;
	    return 0;
	}
	else if (e[i].a.y==e[i].b.y && e[i].a.y==p1.y &&
		 e[i].a.x<=p1.x && e[i].b.x >=p1.x){
	    cout << "BORDER" << endl;
	    return 0;
	}
    }

    int k=0;
    for (int i=1;i<=n;++i){
	if ((e[i].a.y == e[i].b.y) && (e[i].a.y>p1.y) &&
	    (e[i].a.x<p1.x) && (e[i].b.x>=p1.x))
	    k++;
    }
    //print
    if (k & 1==1) cout << "INSIDE" << endl;
    else cout << "OUTSIDE" << endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值