[UVA] 1039 - Simplified GSM Network@Morris' Blog|PChome Online 人新台
2013-10-11 08:43:54| 人2,143| 回0 | 上一篇 | 下一篇

[UVA] 1039 - Simplified GSM Network

0 收藏 0 0 站台

Mobile phones have changed our lifestyle dramatically in the last decade. Mobile phones have a variety of protocols to connect with one another. One of the most popular networks for mobile phones is the GSM (Global System for Mobile Communication) network.


In a typical GSM network, a mobile phone connects with the nearest BTS (Base Transceiver Station). A BSC (Base Station Center) controls several BTSs. Several BSCs are controlled by one MSC (Mobile Services Switching Center), and this MSC maintains a connection with several other MSCs, a PSTN (Public Switched Telecom Network) and an ISDN (Integrated Services Digital Network).


This problem uses a simplified model of the conventional GSM network. Our simplified network is composed of up to fifty BTS towers. When in use, a mobile phone always connects to its nearest BTS tower. The area covered by a single BTS tower is called a cell. When an active mobile phone is in motion, as it crosses cell boundaries it must seamlessly switch from one BTS to another. Given the description of a map consisting of cities, roads and BTS towers, you must determine the minimum number of BTS switches required to go from one city to another.

epsfbox{p3270.eps}

Figure: Cities here are represented by squares and BTS towers by trapezoids. Solid lines are roads. The dotted lines show 9 different cells. The minimum number of switches required to go from city 1 to city 6 is (2+1+0)=3. Note that city 7 is isolated and cannot be reached.

Each tower and each city location is to be considered as a single point in a two-dimensional Cartesian coordinate system. If there is a road between two cities, assume that the road is a straight line segment connecting these two cities. For example, in the figure, traveling on the road from city 1 to city 2 will cross two cell boundaries and thus requires two switches. Traveling from city 2 to city 5 crosses one cell boundary and traveling from city 5 to city 6 requires no switch. Traveling this route from city 1 to city 6 requires three total switches. Note than any other path from city 1 to city 6 requires more than three switches. If there is more than one possible way to get from one city to another, your program must find the optimal route.

Input 

The input file contains several test cases. The first line of each test case contains four integers: B(1$ le$B$ le$50), the number of BTS towers; C(1$ le$C$ le$50), the number of cities; R(0$ le$R$ le$250), the number of roads; and Q(1$ le$Q$ le$10), the number of queries. Each of the next B lines contains two floating-point numbers x and y/i>, the Cartesian coordinates of a BTS tower. Each of the next C lines contains two floating-point numbers xi, yi that indicate the Cartesian coordinates of the ith city (1$ le$i$ le$C). Each of the next R lines contains two integers m and n (1$ le$m, n$ le$C), which indicate that there is a road between the m-th and the n-th city. Each of the next Q lines contains two integers s and d (1$ le$s, d$ le$C), the source and destination cities.


No coordinate will have an absolute value greater than 1000. No two towers will be at the same location. No two cities will be at the same location, and no city will lie on a cell boundary. No road will be coincident with a cell boundary, nor contain a point lying on the boundary of three or more cells.


The input will end with a line containing four zeros.

Output 

For each input set, you should produce Q + 1 lines of output, as shown below. The first line should contain the number of the test case. Q lines should follow, one for each query, each containing an integer indicating the minimum number of switches required to go from city s to city d. If it is not possible to go from city s to city d, print the line `Impossible' instead.

Sample Input 

9 7 6 2 5 5 15 5 25 5 5 15 15 15 25 15 5 25 15 25 25 25 8 2 22 3 8 12 18 18 22 12 28 16 28 8 1 2 1 3 2 5 3 4 4 5 5 6 1 6 1 7 0 0 0 0 

Samle Output 

Case 1: 3 Impossible

目描述:

行手找最接近服台,因此在移,可能移到另一更近的服台。
定服台位置,以及可能的移路,算最少交的次抵目的地。

目解法:

於一路段要找到其中有多少交次,得到所有路的重後,做一次最短路即可。

用求段的重,如果端都坐落於同一服台,那中那一段必然不有交的可能。

便能明白,端分向同一服台,而半以端心。

如果要存在中一段於的服台,必然服台在,假矛盾,因此不可能。

#include <stdio.h>
#include <math.h>
#include <algorithm>
#define eps 1e-8
using namespace std;
double Bx[55], By[55], Cx[55], Cy[55];
int B, C, R, Q;
double lenV(double lx, double ly, double rx, double ry) {
return (lx-rx)*(lx-rx)+(ly-ry)*(ly-ry);
}
int findConnect(double x, double y) {
static int i, ret = 0;
static double mn, t;
mn = 1e+30;
for(i = 0; i < B; i++) {
t = lenV(Bx[i], By[i], x, y);
if(t < mn) mn = t, ret = i;
}
return ret;
}
int getWeight(double lx, double ly, double rx, double ry) {
int l, r;
l = findConnect(lx, ly);
r = findConnect(rx, ry);
if(l == r) return 0;
if(lenV(lx, ly, rx, ry) < eps) return 1;
return getWeight(lx, ly, (lx+rx)/2, (ly+ry)/2)+
getWeight((lx+rx)/2, (ly+ry)/2, rx, ry);
}
int main() {
int cases = 0;
int i, j, k, x, y;
while(scanf("%d %d %d %d", &B, &C, &R, &Q) == 4) {
if(B+C+R+Q == 0)
break;
for(i = 0; i < B; i++)
scanf("%lf %lf", &Bx[i], &By[i]);
for(i = 0; i < C; i++)
scanf("%lf %lf", &Cx[i], &Cy[i]);
int g[55][55];
for(i = 0; i < C; i++) {
for(j = 0; j < C; j++)
g[i][j] = 0xfffffff;
g[i][i] = 0;
}
for(i = 0; i < R; i++) {
scanf("%d %d", &x, &y);
x--, y--;
g[x][y] = g[y][x] = getWeight(Cx[x], Cy[x], Cx[y], Cy[y]);
}
for(k = 0; k < C; k++)
for(i = 0; i < C; i++)
for(j = 0;j < C; j++)
g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
printf("Case %d:\n", ++cases);
while(Q--) {
scanf("%d %d", &x, &y);
x--, y--;
if(g[x][y] == 0xfffffff)
puts("Impossible");
else
printf("%d\n", g[x][y]);
}
}
return 0;
}
 

台: Morris
人(2,143) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 教育(修、留、研究、教育概) | 人分: UVA |
此分下一篇:[UVA][散化&描&BIT] 10869 - Brownie Points II
此分上一篇:[UVA][散化&dp] 1092 - Tracking Bio-bots

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86