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. Drone - 安装,搭配 GitLab 下的配置和使用

    参考资料: Drone 官网地址:https://drone.io Drone 的 GitHub 地址:https://github.com/drone/drone 简介:https://imnerd ...

  2. Python笔记(十四)_永久存储pickle

    pickle模块:将所有的Python对象转换成二进制文件存放 应用场景:编程时最好将大对象(列表.字典.集合等)用pickle写成永久数据包供程序调用,而不是直接写入程序 写入过程:将list转换为 ...

  3. CentOS防火墙命令集

    1. firewalld的基本使用 启动防火墙: systemctl start firewalld 防火墙状态: systemctl status firewalld 停止防火墙: systemct ...

  4. 继承Process类,另一种方法计算累加和以及阶乘

    #定义一个类 继承Process类 from multiprocessing import Process import os import time class jiecheng(Process): ...

  5. JAVA中JavaBean对象之间属性拷贝的方法

    JAVA中JavaBean对象之间的拷贝通常是用get/set方法,但如果你有两个属性相同的JavaBean或有大部分属性相同的JavaBean,对于这种情况,可以采用以下几个简便方法处理. 下面对这 ...

  6. 提交代码到github

    1. 下载git 点击download下载即可.下载地址:https://gitforwindows.org/ 2. 注册github github地址:https://github.com/ 一定要 ...

  7. 动态规划——稀疏表求解RMQ问题

    RMQ (Range Minimum/Maximum Query)问题,即区间最值查询问题,是求解序列中的某一段的最值的问题.如果只需要询问一次,那遍历枚举(复杂度O(n))就是最方便且高效的方法,但 ...

  8. Manacher(最长回文串)

    http://acm.hdu.edu.cn/showproblem.php?pid=3068 最长回文 Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符 ...

  9. stringstream流分割空格

    1205 单词翻转 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze       题目描述 Description 给出一个英语句子,希望你把句子里的单词顺序都翻转 ...

  10. 18、NumPy——矩阵库(Matrix)

    NumPy 矩阵库(Matrix) NumPy 中包含了一个矩阵库 numpy.matlib,该模块中的函数返回的是一个矩阵,而不是 ndarray 对象. 一个 的矩阵是一个由行(row)列(col ...