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]
  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 const double inf = 1000000000.0;
  4 const double ESP = 1e-5;
  5 const int MAX_N = 1000;
  6 const double o = 2.5*sqrt(3.0);
  7 struct Point
  8 {
  9     double x, y;
 10 };
 11 struct LineSegment
 12 {
 13     Point pt1, pt2;
 14 };
 15 typedef vector<Point> Polygon;
 16 Polygon pp;
 17 double Multiply(Point p1, Point p2, Point p0)
 18 {
 19     return ( (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) );
 20 }
 21 bool IsOnline(Point point, LineSegment line)
 22 {
 23     return( ( fabs(Multiply(line.pt1, line.pt2, point)) < ESP ) &&
 24             ( ( point.x - line.pt1.x ) * ( point.x - line.pt2.x ) <= 0 ) &&
 25             ( ( point.y - line.pt1.y ) * ( point.y - line.pt2.y ) <= 0 ) );
 26 }
 27 bool Intersect(LineSegment L1, LineSegment L2)
 28 {
 29     return( (max(L1.pt1.x, L1.pt2.x) >= min(L2.pt1.x, L2.pt2.x)) &&
 30             (max(L2.pt1.x, L2.pt2.x) >= min(L1.pt1.x, L1.pt2.x)) &&
 31             (max(L1.pt1.y, L1.pt2.y) >= min(L2.pt1.y, L2.pt2.y)) &&
 32             (max(L2.pt1.y, L2.pt2.y) >= min(L1.pt1.y, L1.pt2.y)) &&
 33             (Multiply(L2.pt1, L1.pt2, L1.pt1) * Multiply(L1.pt2, L2.pt2, L1.pt1) >= 0) &&
 34             (Multiply(L1.pt1, L2.pt2, L2.pt1) * Multiply(L2.pt2, L1.pt2, L2.pt1) >= 0)
 35           );
 36 }
 37 /* 射线法判断点q与多边形polygon的位置关系,要求polygon为简单多边形,顶点逆时针排列
 38  如果点在多边形内: 返回0
 39  如果点在多边形边上: 返回1
 40  如果点在多边形外: 返回2
 41 */
 42 bool InPolygon(const Polygon& polygon, Point point)
 43 {
 44     int n = polygon.size();
 45     int count = 0;
 46     LineSegment line;
 47     line.pt1 = point;
 48     line.pt2.y = point.y;
 49     line.pt2.x = - inf;
 50
 51     for( int i = 0; i < n; i++ )
 52     {
 53         LineSegment side;
 54         side.pt1 = polygon[i];
 55         side.pt2 = polygon[(i + 1) % n];
 56
 57         if( IsOnline(point, side) )
 58         {
 59             return 1;
 60         }
 61
 62         if( fabs(side.pt1.y - side.pt2.y) < ESP )
 63         {
 64             continue;
 65         }
 66
 67         if( IsOnline(side.pt1, line) )
 68         {
 69             if( side.pt1.y > side.pt2.y ) count++;
 70         }
 71         else if( IsOnline(side.pt2, line) )
 72         {
 73             if( side.pt2.y > side.pt1.y ) count++;
 74         }
 75         else if( Intersect(line, side) )
 76         {
 77             count++;
 78         }
 79     }
 80
 81     if ( count % 2 == 1 )
 82     {
 83         return 0;
 84     }
 85     else
 86     {
 87         return 2;
 88     }
 89 }
 90 void gao (int xx,int yy)
 91 {
 92     pp.clear();
 93     Point heart;
 94     heart.y = yy*2*o*0.5*sqrt(3);
 95     heart.x = yy*o+xx*2*o;
 96     Point p1;
 97     p1.x=heart.x;p1.y=heart.y+5.0;
 98
 99     Point p2;
100     p2.x=heart.x+o;p2.y=heart.y+2.5;
101
102     Point p3;
103     p3.x=heart.x+o;p3.y=heart.y-2.5;
104
105     Point p4;
106     p4.x=heart.x;p4.y=heart.y-5.0;
107
108     Point p5;
109     p5.x=heart.x-o;p5.y=heart.y-2.5;
110
111     Point p6;
112     p6.x=heart.x-o;p6.y=heart.y+2.5;
113
114     pp.push_back(p1);
115     pp.push_back(p2);
116     pp.push_back(p3);
117     pp.push_back(p4);
118     pp.push_back(p5);
119     pp.push_back(p6);
120
121 }
122 int main()
123 {
124     //freopen("de.txt","r",stdin);
125     double xx,yy;
126     vector <pair <int ,int>> ans;
127     while (~scanf("%lf%lf",&xx,&yy)){
128         Point nowpt;
129         nowpt.x=xx,nowpt.y=yy;
130         bool f=false;
131         for (int i=-9;i<=10;++i){
132             for (int j=-9;j<=10;++j){
133                 if (!f){
134                     gao(i,j);
135                     if (InPolygon(pp,nowpt)==0){
136                         ans.push_back(make_pair(i,j));
137                         f=true;
138                         break;
139                     }
140                 }
141
142             }
143         }
144
145     }
146     int sz = ans.size();
147     for (int i=0;i<sz;++i){
148         printf("[%d,%d]",ans[i].first,ans[i].second);
149         if (i!=sz-1){
150             printf(", ");
151         }
152         else{
153             printf("\n");
154         }
155
156     }
157     return 0;
158 }
 
时间: 2024-10-15 18:04:18

2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification (点在多边形内模板)的相关文章

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

摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5984 Pocky 题意 给出一根棒子(可以吃的)的长度x和切割过程中不能小于的长度d,每次随机的选取一个位置切开,吃掉左边的一半,对右边的棒子同样操作,直至剩余的长度不大于d时停止.现在给出x和d,问切割次数的数学期望是多少. 解题思路 当看到第二个样例2 1时,结果是1.693147,联想到ln

2014ACM/ICPC亚洲区鞍山赛区现场赛——题目重现

2014ACM/ICPC亚洲区鞍山赛区现场赛--题目重现 题目链接 5小时内就搞了5题B.C.D.E,I. H题想到要打表搞了,可惜时间不够,后面打出表试了几下过了- - K题过的人也比较多,感觉是个几何旋转+ploya,但是几何实在不行没什么想法 B:这题就是一个大模拟,直接数组去模拟即可,注意细节就能过 C:类似大白上一题红蓝三角形的, 每个数字找一个互质和一个不互质个数,除掉重复就直接除2,然后总的C(n, 3)减去即可,问题在怎么处理一个数字互质和不互质的,其实只要处理出不互质的即可,这

ICPC 2018 徐州赛区网络赛

ACM-ICPC 2018 徐州赛区网络赛 ?去年博客记录过这场比赛经历:该死的水题 ?一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. ? ? D. Easy Math 题意: ? 给定 \(n\), \(m\) ,求 \(\sum _{i=1}^{m} \mu(in)\) .其中 $ 1 \le n \le 1e12$ , $ 1 \le m \le 2e9$ ,\(\mu(n)\) 为莫比乌斯函数. ? 思路: ? 容易知道,\(i\) 与 \(n\) 不互质时, \(\m

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

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit    1000 ms Memory limit 65536 kB OS Windows We have a special convex that all points have the same distance to origin point. As you know we can get N segments after linki

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

鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 5078 Appoint description:  System Crawler  (2014-10-22) Description Osu! is a very popular music game. B

2017ICPC南宁赛区网络赛 The Heaviest Non-decreasing Subsequence Problem (最长不下降子序列)

Let SSS be a sequence of integers s1s_{1}s?1??, s2s_{2}s?2??, ........., sns_{n}s?n?? Each integer is is associated with a weight by the following rules: (1) If is is negative, then its weight is 000. (2) If is is greater than or equal to 10000100001

GSM Base Station Identification 2017南宁网络赛

emmm...... 我上小学开始就不打小报告了 emmm...... 话太多就变菜了 1 #include<bits/stdc++.h> 2 #define cl(a,b) memset(a,b,sizeof(a)) 3 #define debug(a) cerr<<#a<<"=="<<a<<endl 4 using namespace std; 5 typedef long long ll; 6 typedef pair&

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri

hdu5512 Pagodas(2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学) )

Pagodas Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 14 Accepted Submission(s): 13 Problem Description n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai M