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 (点在多边形内模板)的更多相关文章

  1. 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 ...

  2. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  3. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  4. ICPC 2018 徐州赛区网络赛

    ACM-ICPC 2018 徐州赛区网络赛  去年博客记录过这场比赛经历:该死的水题  一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进.     D. Easy Math 题意:   ...

  5. Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)

    参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...

  6. [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题

    第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...

  7. 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit    1000 ms Memory li ...

  8. 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!

    鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Fo ...

  9. 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 ...

随机推荐

  1. 学院-成就学院:Academy of Achievement

    ylbtech-学院-成就学院:Academy of Achievement 1.返回顶部 1. https://www.achievement.org/ 2. https://www.achieve ...

  2. python内置装饰器

    前言 接着上一篇笔记,我们来看看内置装饰器property.staticmethod.classmethod 一.property装饰器 1. 普通方式修改属性值 code class Celsius ...

  3. -bash: ./hello.jar: 无法执行二进制文件

    在linux中直接调用java包产生的 解决:依赖多个包要用冒号分隔,而不是分号 正确:> java -cp ./lib/*:./hello.jar hello 错误:> java -cp ...

  4. delphi 神经网络 学习

    https://github.com/uldercarrilho/ParallelNeuralNetwork

  5. 字符串模式匹配算法系列(二):KMP算法

    算法背景: KMP算法是由Donald Knuth和Vaughan Pratt于1970年共同提出的,而James H.Morris也几乎同时间独立提出了这个算法.因此人们将其称作“克努特-莫里斯-普 ...

  6. 学习ECMAScript标准和具体实现-JavaScript

    在NDN的JavaScript Guide里,Array和Map,Set都属于collections of data.它们的区别就是,Array是ordered by an index value,  ...

  7. hive 排序

    1.全局排序(order by) Order by:全局排序,只有一个reducer ASC(ascend):升序(默认) DESC(descend):降序 2.每个MR内部排序(sort by) s ...

  8. HDFS-NameNode和SeconddaryNode

    一.NN和2N的工作机制 一.概述 一.概述 一.概述 一.概述 一.概述 一.概述 一.概述

  9. centos nginx 设置开启启动

    1 vi /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkco ...

  10. MVC与设计模式的关系及MVC的实现原理和设计原理

    1 MVC介绍 众所周知MVC不是设计模式,是一个比设计模式更大一点的模式,称作设计模式不合理,应该说MVC它是一种软件开发架构模式,它包含了很多的设计模式,最为密切是以下三种:Observer (观 ...