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. php-mbstring php7.0-zip

    sudo apt install php-mbstring sudo apt install zip unzip php7.0-zip

  2. Embedding理解与代码实现

    https://blog.csdn.net/songyunli1111/article/details/85100616

  3. SHELL脚本里执行的东西需要多次回车确认,怎么实现自动回车确认?

    写了个自动配置的shell脚本,其中有几行是 …… ./build-key-server ./build-key-client …… 在执行build-key-server和build-key-cli ...

  4. 设置chrome解决跨域问题

    开发中遇到跨域问题, 解决方法一 以关闭安全验证模式启动chrome,就不会报跨域了  开发阶段,用这个方式是可以的,不然他需要后台配置成 * , 发布会有风险  设置方法:  --disable-w ...

  5. 【python】 判断纯ascii串

    参考:http://stackoverflow.com/questions/3636928/test-if-a-python-string-is-printable print all(ord(c)& ...

  6. kmp(多次无重叠匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2087 剪花布条 Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面 ...

  7. Assembly language 再读---续

    前面已经写到了第三章的数据类型 的那一部分 接下来是一些关于伪指令和其他杂七杂八的东西 1. 当前地址计数器:   $ 常用于  计算数组以及字符串的长度,如: .data list db ,,,,, ...

  8. 54-python基础-python3-字符串-字符串类型及其转换

    1-Python3中字符串类型: bytes:二进制 互联网上数据的都是以二进制的方式传输的. str :unicode的呈现形式. 2-Unicode UTF8 ASCII的补充 字符(Charac ...

  9. 攻防世界--Hello, CTF

    测试文件地址:https://www.lanzous.com/i5ot1yd 使用IDA1打开 打开之后,这个字符串和第一题的有些类似,拿去转换一下,Flag就得到了 CrackMeJustForFu ...

  10. 为什么需要在 React 类组件中为事件处理程序绑定this?

    https://juejin.im/post/5afa6e2f6fb9a07aa2137f51 事件绑定作为回调函数参数传递给函数,丢失其上下文,执行的是默认绑定,不是隐式绑定 类声明和类表达式的主体 ...