2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification (点在多边形内模板)
In the Personal Communication Service systems such as GSM (Global System for Mobile Communications), there are typically a number of base stations spreading around the service area. The base stations are arranged in a cellular structure, as shown in the following figure. In each cell, the base station is located at the center of the cell.
For convenience, each cell is denoted by [ii, jj]. The cell covers the origin is denoted by [00, 00]. The cell in the east of [00, 00] is denoted by [11, 00]. The cell in the west of [00, 00] is denoted by [-1−1, 00]. The cell in the northeast of [00, 00] is denoted by [00, 11]. The cell in the southwest of [00, 00] is denoted by [00, -1−1]. This notation can be easily generalized, as shown in the above figure.
Now the question is as follows. We have a service area represented by a Euclidean plane (i.e., x-yx−y plane). Each unit is 11 Km. For example, point (55, 00) in the plane means the location at a distance of 55 Km to the east of the origin. We assume that there are totally 400400 cells, denoted by [ii, jj], i\ =\ -9 \ ... \ 10i = −9 ... 10, j\ =\ -9\ ... \ 10j = −9 ... 10. The base station of cell [00, 00] is located at the origin of the Euclidean plane. Each cell has a radius of RR = 55 Km, as shown in the following figure.
You are given an input (xx, yy), which indicates a mobile phone’s location. And you need to determine the cell [ii, jj] that covers this mobile phone and can serve this phone call.
For example, given a location (1010, 00), your program needs to output the cell [11, 00], which can cover this location. Specifically, the input and output are:
- input = (xx, yy). hhis is a location on the Euclidean plane. This value will not exceed the service area covered by the 400400 cells. That is, you do not need to handle the exceptional case that the input is out of the boundary of the service area.
- output = [ii, jj]. One of the 400400 cells that covers location [ii, jj]
Input Format
A list of 1010 locations.
Output Format
A list of 1010 cells covering the above 1010 locations in the correct order.
Please be reminded that there exist a space between coordinates.
样例输入
1 0
0 15
2 0
13 7
5 5
10 15
25 15
-13 -8
12 -7
-10 0
样例输出
[0,0], [-1,2], [0,0], [1,1], [0,1], [0,2], [2,2], [-1,-1], [2,-1], [-1,0]
#include <bits/stdc++.h>
using namespace std;
const double inf = 1000000000.0;
const double ESP = 1e-;
const int MAX_N = ;
const double o = 2.5*sqrt(3.0);
struct Point
{
double x, y;
};
struct LineSegment
{
Point pt1, pt2;
};
typedef vector<Point> Polygon;
Polygon pp;
double Multiply(Point p1, Point p2, Point p0)
{
return ( (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) );
}
bool IsOnline(Point point, LineSegment line)
{
return( ( fabs(Multiply(line.pt1, line.pt2, point)) < ESP ) &&
( ( point.x - line.pt1.x ) * ( point.x - line.pt2.x ) <= ) &&
( ( point.y - line.pt1.y ) * ( point.y - line.pt2.y ) <= ) );
}
bool Intersect(LineSegment L1, LineSegment L2)
{
return( (max(L1.pt1.x, L1.pt2.x) >= min(L2.pt1.x, L2.pt2.x)) &&
(max(L2.pt1.x, L2.pt2.x) >= min(L1.pt1.x, L1.pt2.x)) &&
(max(L1.pt1.y, L1.pt2.y) >= min(L2.pt1.y, L2.pt2.y)) &&
(max(L2.pt1.y, L2.pt2.y) >= min(L1.pt1.y, L1.pt2.y)) &&
(Multiply(L2.pt1, L1.pt2, L1.pt1) * Multiply(L1.pt2, L2.pt2, L1.pt1) >= ) &&
(Multiply(L1.pt1, L2.pt2, L2.pt1) * Multiply(L2.pt2, L1.pt2, L2.pt1) >= )
);
}
/* 射线法判断点q与多边形polygon的位置关系,要求polygon为简单多边形,顶点逆时针排列
如果点在多边形内: 返回0
如果点在多边形边上: 返回1
如果点在多边形外: 返回2
*/
bool InPolygon(const Polygon& polygon, Point point)
{
int n = polygon.size();
int count = ;
LineSegment line;
line.pt1 = point;
line.pt2.y = point.y;
line.pt2.x = - inf; for( int i = ; i < n; i++ )
{
LineSegment side;
side.pt1 = polygon[i];
side.pt2 = polygon[(i + ) % n]; if( IsOnline(point, side) )
{
return ;
} if( fabs(side.pt1.y - side.pt2.y) < ESP )
{
continue;
} if( IsOnline(side.pt1, line) )
{
if( side.pt1.y > side.pt2.y ) count++;
}
else if( IsOnline(side.pt2, line) )
{
if( side.pt2.y > side.pt1.y ) count++;
}
else if( Intersect(line, side) )
{
count++;
}
} if ( count % == )
{
return ;
}
else
{
return ;
}
}
void gao (int xx,int yy)
{
pp.clear();
Point heart;
heart.y = yy**o*0.5*sqrt();
heart.x = yy*o+xx**o;
Point p1;
p1.x=heart.x;p1.y=heart.y+5.0; Point p2;
p2.x=heart.x+o;p2.y=heart.y+2.5; Point p3;
p3.x=heart.x+o;p3.y=heart.y-2.5; Point p4;
p4.x=heart.x;p4.y=heart.y-5.0; Point p5;
p5.x=heart.x-o;p5.y=heart.y-2.5; Point p6;
p6.x=heart.x-o;p6.y=heart.y+2.5; pp.push_back(p1);
pp.push_back(p2);
pp.push_back(p3);
pp.push_back(p4);
pp.push_back(p5);
pp.push_back(p6); }
int main()
{
//freopen("de.txt","r",stdin);
double xx,yy;
vector <pair <int ,int>> ans;
while (~scanf("%lf%lf",&xx,&yy)){
Point nowpt;
nowpt.x=xx,nowpt.y=yy;
bool f=false;
for (int i=-;i<=;++i){
for (int j=-;j<=;++j){
if (!f){
gao(i,j);
if (InPolygon(pp,nowpt)==){
ans.push_back(make_pair(i,j));
f=true;
break;
}
} }
} }
int sz = ans.size();
for (int i=;i<sz;++i){
printf("[%d,%d]",ans[i].first,ans[i].second);
if (i!=sz-){
printf(", ");
}
else{
printf("\n");
} }
return ;
}
2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification (点在多边形内模板)的更多相关文章
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem【状态压缩】
2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem 题意:给定N和α还有M个U={1,2,3,...N}的子集,求子集X个数,X满足:X是U ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)
摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...
- ICPC 2018 徐州赛区网络赛
ACM-ICPC 2018 徐州赛区网络赛 去年博客记录过这场比赛经历:该死的水题 一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. D. Easy Math 题意: ...
- Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)
参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...
- [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题
第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...
- 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit 1000 ms Memory li ...
- 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!
鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS Memory Limit:262144KB 64bit IO Fo ...
- 2017ICPC南宁赛区网络赛 Minimum Distance in a Star Graph (bfs)
In this problem, we will define a graph called star graph, and the question is to find the minimum d ...
随机推荐
- python比C程序相比非常慢
w http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001374738136930 ...
- Mac下隐藏或显示文件/文件夹
命令行操作 显示:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏:defaults write com.apple.fi ...
- MySql 5.7.20 绿色版安装
MySql 5.7.20 绿色版安装 一.MySql 安装 1.从官网下载绿色压缩包. 2.解压安装文件到指定目录 3.创建配置文件 my.ini 到解压文件的根目录,my.ini 配置文件如下,需将 ...
- 140、spring webflux 高并发的spring组件
最近公司可谓是风云变幻,年前说要拆开卖,后来说要整体卖,表示像我这种渣渣,始终逃脱不掉被卖的命运 下面进入正题 spring webflux 是spring 支持的高并发web框架,将每个http请求 ...
- 让dcef3支持mp3和h.264 mp4解码播放
嵌入式Chromium框架(简称CEF) 是一个由Marshall Greenblatt在2008建立的开源项目,它主要目的是开发一个基于Google Chromium的Webbrowser控件.CE ...
- Caffe深入分析(源码)
Caffe的整体流程图: 程序入口:main() int main(int argc, char** argv) { ..... ]))(); .... } g_brew_map实现过程,首先通过 t ...
- Selenium WebDriver 常用API
public class Demo1 { WebDriver driver; @BeforeMethod public void visit(){ //webdriver对象的声明 System.se ...
- Java thread(1)
这一部分主要讨论 java多线程的基本相关概念以及两种java线程的实现方式: 线程与进程: 这个操作系统书上介绍得很详细,这里就列出一些比较主要的: 线程: 线程本身有很少的资源,因为所拥有的资源较 ...
- 《STL源码剖析》——第五、六:关联容器与算法
第五章.关联容器 5.0.关联容器 标准的STL关联式容器分为set(集合)和map(映射表)两大类,以及这两大类的衍生体multiset(多键集合)和multimap(多键映射表).这些容器的底层 ...
- Day6----Python的pyinstall库的使用
Python的pyinstaller库 pyinstaller的安装 介绍:pyinstaller是Python的第三方库,主要用于将Python代码打包成 可执行文件 ,以此达到就算没安装P ...