美文网首页
HDU4643——GSM

HDU4643——GSM

作者: xz闲语岁月 | 来源:发表于2017-08-02 21:20 被阅读0次

Problem

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.

Input

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.

Output

For each query, tell Xiao Ming how many times the base station will change from city a to city b.

Sample Input

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

Sample Output

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.


思路

计算几何题。从一点到另一点的过程中,不断二分即可。

代码

#include<bits/stdc++.h>
#define eps 1e-8
using namespace std;
struct Point {
    double x, y;
    Point() {};
    Point(double _x, double _y) :x(_x), y(_y) {};
    double Dist(const Point p) {
        return sqrt((x - p.x)*(x - p.x) + (y - p.y)*(y - p.y));
    }
    Point Mid(const Point p) {
        return Point((x + p.x) / 2, (y + p.y) / 2);
    }
    friend istream& operator>>(istream& is, Point &p) {
        is >> p.x >> p.y;
        return is;
    }
};
Point c[55], s[55];
int n, m, t, a, b;
void Init() {
    memset(c, 0, sizeof(c));
    memset(s, 0, sizeof(s));
}
int Search(Point p) {
    int res = 1;
    double min_dist = p.Dist(s[1]);
    for (int i = 2; i <= m; i++) {
        double dist = p.Dist(s[i]);
        if (dist<min_dist) { res = i; min_dist = dist; }
    }
    return res;
}
int Solve(Point a, Point b) {
    int p = Search(a), q = Search(b);
    if (p == q)return 0;
    else if (a.Dist(b)<eps)return 1;
    else {
        Point mid = a.Mid(b);
        return Solve(a, mid) + Solve(mid, b);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> n >> m) {
        Init();
        for (int i = 1; i <= n; i++)cin >> c[i];
        for (int i = 1; i <= m; i++)cin >> s[i];
        cin >> t;
        while (t--) {
            cin >> a >> b;
            cout << Solve(c[a], c[b]) << endl;
        }
    }
    return 0;
}

相关文章

  • HDU4643——GSM

    Problem Xiao Ming is traveling around several cities by t...

  • YY1

    GM12891GSM803535GSM803467 HCT-116GSM803354GSM803475 HepG2...

  • GSM系统

    GSM概述 1.1.1GSM组网图 1.1.2GSM协议栈概述 整个GSM协议栈如下图所示。其中,Um口是UE和基...

  • GSM

    gsm无法进行软切换。曾经有传闻说爱立信公司再研发gsm的软切换,但一直未见。 软切换的必要条件: 1、在进行切换...

  • 每日科技英文25: GSM/CDMA/SIM概念

    今日要点: GSM/CDMA/SIM 同位语与从句概念 GSM(Global System for Mobile)...

  • 图解射频天线指标,秒懂!

    GSM/WCDMA/TDSCDMA/LTE/5G NR的帧结构。 GSM Frame Structure WCDM...

  • 手机开发实战12——GSM规范简介

    GSM的目前规范版本是出现于1997年第二阶段增强版本(GSM Phase 2+),以下是GSM规范各个版本之间的...

  • GSM模块

    GSM模块,是将GSM射频芯片、基带处理芯片、存储器、功放器件等集成在一块线路板上,具有独立的操作系统、GSM射频...

  • SRRC无线电发射设备名称

    SRRC无线电发射设备名称 : 一、公众移动通信设备: 1. GSM/CDMA/蓝牙手机 2. GSM/CDMA/...

  • 《大话移动通信》p141-162

    继续介绍GSM网络,第三GSM的编号计划需要满足以下两个条件:一是唯一性,二是标志要方便检索。分别介绍了在GSM网...

网友评论

      本文标题:HDU4643——GSM

      本文链接:https://www.haomeiwen.com/subject/nbgylxtx.html