HDU 4643 GSM (2013多校5 1001题 计算几何)
2013-08-07 20:07
363 查看
GSM
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 622 Accepted Submission(s): 206
[align=left]Problem Description[/align]
Xiao Ming is traveling around several cities by train. And the time on the train is very boring, so Xiao Ming will use the mobile Internet. We all know that mobile phone receives the signal from base station and it will change the base station when moving on the train. Xiao Ming would like to know how many times the base station will change from city A to city B.
Now, the problem is simplified. We assume the route of train is straight, and the mobile phone will receive the signal from the nearest base station.
[align=left]Input[/align]
Multiple cases. For each case, The first line: N(3<=N<=50) - the number of cities, M(2<=M<=50) - the number of base stations. Then there are N cities with coordinates of (x, y) and M base stations with coordinates of (x, y) - (0<=x<=1000, 0<=y<=1000, both x and y is integer).Then there is a number : K, the next, there are K queries, for each query, each line, there are two numbers: a, b.
[align=left]Output[/align]
For each query, tell Xiao Ming how many times the base station will change from city a to city b.
[align=left]Sample Input[/align]
4 4
0 2
1 3
1 0
2 0
1 2
1 1
2 2
2 1
4
1 2
1 3
1 4
3 4
[align=left]Sample Output[/align]
0
1
2
1
Hint
The train way from a to b will not cross the point with the same distance from more than 2 base stations.
(For the distance d1 and d2, if fabs(d1-d2)<1e-7, we think d1 == d2).
And every city exactly receive signal from just one base station.
[align=left]Source[/align]
2013 Multi-University Training Contest 5
[align=left]Recommend[/align]
zhuyuanchen520
在从u->v的路径上,不断分成两段去做。
很简单
#include <stdio.h> #include <algorithm> #include <iostream> #include <string.h> #include <queue> #include <map> #include <set> #include <vector> #include <string> #include <math.h> #include <time.h> using namespace std; const double eps = 1e-8; struct Point { double x,y; Point(){} Point(double _x,double _y) { x = _x;y = _y; } void input() { scanf("%lf%lf",&x,&y); } }; //*两点间距离 inline double dis(Point a,Point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } Point p1[55],p2[55]; int n,m; inline int Belong(Point p) { int k = 0; double d = dis(p,p2[0]); for(int i = 1;i < m;i++) { double d2 = dis(p,p2[i]); if(d2 < d) { d = d2; k = i; } } return k; } int solve(Point a,Point b) { int k1 = Belong(a); int k2 = Belong(b); if(k1 == k2)return 0; if(dis(a,b)<eps)return 1; Point t = Point((a.x+b.x)/2,(a.y+b.y)/2); return solve(a,t)+solve(t,b); } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%d%d",&n,&m) == 2) { for(int i = 0;i < n;i++) p1[i].input(); for(int i = 0;i < m;i++) p2[i].input(); int K; int u,v; scanf("%d",&K); while(K--) { scanf("%d%d",&u,&v); u--;v--; printf("%d\n",solve(p1[u],p1[v])); } } return 0; }
相关文章推荐
- HDU 4643 GSM 简单计算几何 (2013多校联合)
- hdu 4629 计算几何 扫描线 (2013多校联合)
- HDU 4643 GSM 简单计算几何
- 2013 多校第七场 hdu 4667 Building Fence(计算几何、凸包)
- HDU 4643 GSM 暑期多校联合训练第五场 1001
- HDU 4643 GSM(计算几何)
- HDU 4643 GSM(计算几何求线段的中垂线)
- hdu 4643 GSM 计算几何 - 点线关系
- HDU 4643 GSM 暑期多校联合训练第五场 1001
- hdu 4643 GSM 计算几何 - 点线关系
- hdu 4617 2013多校联合训练第二场weapon简单的计算几何
- HDU 4410 Boomerang(计算几何)(2012杭州网络赛1001)
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
- HDU 4666 Hyperspace(2013多校联合7 1001)
- 2013杭州网络赛D题HDU 4741(计算几何 解三元一次方程组)
- hdu 4643(简单计算几何)
- HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)
- HDU 4632 Palindrome subsequence (2013多校4 1001 DP)
- hdu 4720 Naive and Silly Muggles 外接圆(计算几何) 2013 ACM/ICPC Asia Regional Online —— Warmup2 1005
- hdu 4643 GSM(几何)