tjut 4643

#include <cstdio>
#include <cmath>
const double eps = 1e-8;
inline int dcmp(double x) {
    if(fabs(x) < eps) return 0;
    return x > eps ? 1 : -1;
}
struct point {
    double x, y;
    point(double x, double y) :
            x(x), y(y) {
    }
    point() {
    }
    point operator+(const point &t) const {
        return point(x + t.x, y + t.y);
    }
    point operator-(const point &t) const {
        return point(x - t.x, y - t.y);
    }
    point operator*(const double &t) const {
            return point(x*t, y*t);
    }
    inline void in() {
        scanf("%lf%lf", &x, &y);
    }
} sta[55], city[55], tt, tp;
struct line {
    point a, b;
    line(point a, point b) :
            a(a), b(b) {
    }
    line() {
    }
} l[50][50];
int n, m, k;
inline line getMidLine(const point &a, const point &b) {
    point mid = (a + b) *0.5;
    point tp = b-a;
    return line(mid, mid+point(-tp.y, tp.x));
}

inline double cross(const point &a, const point &b) {
    return a.x*b.y-a.y*b.x;
}
inline point intersect(const point &a, const point &b, const point &l, const point &r) {
    point ret = a;
    double t = ((a.x - l.x) * (l.y - r.y) - (a.y - l.y) * (l.x - r.x))
            / ((a.x - b.x) * (l.y - r.y) - (a.y - b.y) * (l.x - r.x));
    ret.x += (b.x - a.x) * t;
    ret.y += (b.y - a.y) * t;
    return ret;
}
inline bool dotOnSeg(const point &p, const point &l, const point &r) {  //判点在线段上
    return (p.x-l.x)*(p.x-r.x) < eps
    && (p.y-l.y)*(p.y-r.y) < eps;
}
inline double dis(const point &a, const point &b) {
    return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
inline bool judge(const point &p, int &a) {
    double d = dis(p, sta[a]);
    int i;
    for(i = 0; i < m; i++) if(i != a)
        if(d > dis(p, sta[i])+eps) return 0;
    return 1;
}
int a, b, ans;
int main() {
    int i, j;
    while (~scanf("%d%d", &n, &m)) {
        for (i = 0; i < n; i++) city[i].in();
        for (i = 0; i < m; i++) sta[i].in();
        for (i = 0; i < m; i++)
            for (j = i + 1; j < m; j++)
                l[i][j] = getMidLine(sta[i], sta[j]);

        scanf("%d", &k);
        while(k--) {
            ans = 0;
            scanf("%d%d", &a, &b);
            a--; b--;
            tt = city[a]-city[b];
            for(i = 0; i < m; i++)
                for(j = i+1; j < m; j++) {
                    if(!dcmp(cross(tt, l[i][j].a-l[i][j].b))) continue;
                    tp = intersect(city[a], city[b], l[i][j].a, l[i][j].b);
                    if(dotOnSeg(tp, city[a], city[b]))
                        ans += judge(tp, i);
                }
            printf("%d\n", ans);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值