时间限制:0.25s

空间限制:4M

题意

给出n条线段和一个点,保证所有线段平行X轴或Y,并且闭合成一个多边形。判断这个点的位置是在多边形上,还是多边形内,还是多边形外。

solution

由于,所有的线段都平行于X轴或Y轴且闭合,那么只要判断在点的正上方有多少条线段即可。

如果是奇数,则在多边形内,偶数在多边形外。特判在多边形上的情况。

参考代码

#include <cstdio>
#include <iostream>
using namespace std;
struct node {
int x1, y1, x2, y2;
} f[11111];
int x, y, n, ans;
int main()
{
scanf ("%d", &n);
for (int i = 1; i <= n; ++i)
{
scanf ("%d %d %d %d", &f[i].x1, &f[i].y1, &f[i].x2, &f[i].y2);
if (f[i].x1 > f[i].x2) swap (f[i].x1, f[i].x2);
if (f[i].y1 > f[i].y2) swap (f[i].y1, f[i].y2);
}
scanf ("%d %d", &x, &y);
int ans = 0;
for (int i = 1; i <= n; ++i)
{
if (f[i].x1 == f[i].x2)
if (x == f[i].x1 && f[i].y1 <= y && y <= f[i].y2)
{ puts ("BORDER"); return 0; }
if (f[i].y1 == f[i].y2)
{
if (y == f[i].y1 && f[i].x1 <= x && x <= f[i].x2)
{ puts ("BORDER"); return 0; }
if (f[i].y1 > y && f[i].x1 < x && x <= f[i].x2) ans++;
}
}
if (ans & 1) puts ("INSIDE");
else puts ("OUTSIDE");
return 0;
}

SGU 124.Broken line的更多相关文章

  1. SGU 124. Broken line 射线法 eps的精准运用,计算几何 难度:3

    124. Broken line time limit per test: 0.25 sec. memory limit per test: 4096 KB There is a closed bro ...

  2. Broken line - SGU 124(判断点与多边形的关系)

    题目大意:RT 分析:构造一条射线,如果穿越偶数条边,那么就在多边形外面,如果穿越奇数条边,那么就在多边形里面. 代码如下: ===================================== ...

  3. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  4. 今日SGU 5.9

    SGU 297 题意:就是求余数 收获:无 #include<bits/stdc++.h> #define de(x) cout<<#x<<"=" ...

  5. SGU 128. Snake --- 暴力枚举+并查集+贪心+计算几何

    <传送门> 128. Snake time limit per test: 0.25 sec. memory limit per test: 4096 KB There are N poi ...

  6. all unicode

    Unicode Chart Range Decimal Name 0x0000-0x007F 0-127 Basic Latin 0x0080-0x00FF 128-255 Latin-1 Suppl ...

  7. opencron

    opencron 是强大的管理linux crontab任务的系统,基于JAVA开发 http://github.com/wolfboys/opencron 一个功能完善真正通用的linux定时任务调 ...

  8. JHChart 1.1.0 iOS图表工具库中文ReadMe

    JHChart(最新版本1.1.0) 好吧,的确当前的github上已经存有不少的iOS图表工具库,然而,当公司的项目需要图表时,几乎没有哪个第三方能够完全满足我的项目需求.无奈之下,本人不得不花费一 ...

  9. Transistor 晶体管 场效应 双极型 达林顿 CMOS PMOS BJT FET

    Transistor Tutorial Summary Transistor Tutorial Summary Bipolar Junction Transistor Tutorial We can ...

随机推荐

  1. c#查看电脑内存

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  2. UVa816 Abbott's Revenge

    Abbott's Revenge Time limit: 3.000 seconds Abbott’s Revenge  Abbott’s Revenge The 1999 World FinalsC ...

  3. margin设置为负数

    1.为负margin“平反” 我们在CSS中都会使用margin,但将margin设置成负数,那可能就不大好处理了.在网页设计中,人们对负margin用法的态度大相径庭,有的人非常喜欢,而有的人则认为 ...

  4. 【转】SVN linux命令及 windows相关操作(二)

    转自这里:http://www.uml.org.cn/pzgl/200904246.asp 1 安装及下载client 端 2 什么是SVN(Subversion)? 3 为甚么要用SVN? 4 怎么 ...

  5. t

    http://www.cnblogs.com/courtier/p/4287177.html 360导航_新一代安全上网导航 http://www.cnblogs.com/zhenzi/p/42926 ...

  6. Apache-POI操作Excel的一些小技巧

    Apache-POI操作Excel将合并后的单元格全部填充为相同数据的一个实例. private static void fillMergedRegion(final Sheet sheet) { f ...

  7. UVA 753 - A Plug for UNIX(网络流)

      A Plug for UNIX  You are in charge of setting up the press room for the inaugural meeting of the U ...

  8. 【javascript基础知识】javascript中的转义序列和特殊数值常量

    javascript的转义序列 \0 NUL字符(\u0000) \b 退格符(\u0008) \t 水平制表符(\u0009) \n 换行符(\u000A) \v 垂直制表符(\u000B) \f ...

  9. HTML5事件——contextmenu 隐藏鼠标右键菜单

    在window中单击右键或在Mac中Ctrl+单击时会触发contextmenu事件,通过取消其默认动作能够提供自己定义菜单. 首先先写一个自己的菜单: <style> ul, li { ...

  10. Understanding JTS--reference

    Part I-An introduction to transactions If you look at any introductory article or book on J2EE, you' ...