SGU 124.Broken line
时间限制: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的更多相关文章
- 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 ...
- Broken line - SGU 124(判断点与多边形的关系)
题目大意:RT 分析:构造一条射线,如果穿越偶数条边,那么就在多边形外面,如果穿越奇数条边,那么就在多边形里面. 代码如下: ===================================== ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 今日SGU 5.9
SGU 297 题意:就是求余数 收获:无 #include<bits/stdc++.h> #define de(x) cout<<#x<<"=" ...
- SGU 128. Snake --- 暴力枚举+并查集+贪心+计算几何
<传送门> 128. Snake time limit per test: 0.25 sec. memory limit per test: 4096 KB There are N poi ...
- all unicode
Unicode Chart Range Decimal Name 0x0000-0x007F 0-127 Basic Latin 0x0080-0x00FF 128-255 Latin-1 Suppl ...
- opencron
opencron 是强大的管理linux crontab任务的系统,基于JAVA开发 http://github.com/wolfboys/opencron 一个功能完善真正通用的linux定时任务调 ...
- JHChart 1.1.0 iOS图表工具库中文ReadMe
JHChart(最新版本1.1.0) 好吧,的确当前的github上已经存有不少的iOS图表工具库,然而,当公司的项目需要图表时,几乎没有哪个第三方能够完全满足我的项目需求.无奈之下,本人不得不花费一 ...
- Transistor 晶体管 场效应 双极型 达林顿 CMOS PMOS BJT FET
Transistor Tutorial Summary Transistor Tutorial Summary Bipolar Junction Transistor Tutorial We can ...
随机推荐
- ♫【模式】自定义函数(self-defining function)
<JavaScript模式> /** * 如果创建了一个新函数并且将其分配给保存了另外函数的同一个变量,那么就以一个新函数覆盖旧函数. * 在某种程度上,回收旧函数指针以指向一个新函数.而 ...
- 汇编学习笔记(14)BIOS对键盘输入的处理
字符的处理 键盘输入的字符一般由int9中断例程从60h端口中读取,并存放在键盘缓冲区中,由int16h例程从键盘缓冲区中读取相应字符,CPU对键盘输入a.shift_a的处理过程如下 1.一开始没有 ...
- 游戏开发设计模式之对象池模式(unity3d 示例实现)
前篇:游戏开发设计模式之命令模式(unity3d 示例实现) 博主才学尚浅,难免会有错误,尤其是设计模式这种极富禅意且需要大量经验的东西,如果哪里书写错误或有遗漏,还请各位前辈指正. 原理:从一个固定 ...
- leetcode 最大矩形和
1.枚举法(超时) public class Solution { public int largestRectangleArea(int[] height) { int max=-1; for(in ...
- bzoj 1923 [Sdoi2010]外星千足虫(高斯消元+bitset)
1923: [Sdoi2010]外星千足虫 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 634 Solved: 397[Submit][Status ...
- SRM 409(1-250pt, 1-500pt)
DIV1 250pt 题意:称string s是vector<string> words的ordered superstring,如果它满足:存在一个数列{x0, x1, x2...xm} ...
- MongoDB基础知识 01
MongoDB基础知识 1. 文档 文档是MongoDB中的数据的基本单元,类似于关系型数据库管理系统的行. 文档是键值对的一个有序集.通常包含一个或者多个键值对. 例如: {”greeting& ...
- select、poll、epoll三组IO复用
int select(int nfds,fd_set* readfds,fd_set* writefds,fd_set* exceptfds,struct timeval* timeout)//其中n ...
- 常用文件操作 分类: C# 2014-10-14 16:18 108人阅读 评论(0) 收藏
界面图: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...
- J2EE ssm框架-服务启动项内存加载数据及读取。
1.首先在 Web工程 WEB-INF目录下web.xml中添加 listener: <listener> <listener-class>com.founder.frame. ...