hdu_4643 GSM

二分的思想,很重要  对连续区间的处理

关键点:假如两个点距离很近,他们对应的点依然不同,那么solve()函数返回1

http://acm.hdu.edu.cn/showproblem.php?pid=4643

#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <fstream>
using namespace std;

//LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)

//OTHER
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define all(x) (x).begin(),(x).end()
#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)

//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RS(s) scanf("%s", s)

//OUTPUT
#define WI(n) printf("%d\n", n)
#define WS(n) printf("%s\n", n)

//debug
//#define online_judge

#define enter
#ifndef online_judge
#define debugt(a) cout << (#a) << "=" << a << " ";
#define debugI(a) debugt(a) cout << endl
#define debugII(a, b) debugt(a) debugt(b) cout << endl
#define debugIII(a, b, c) debugt(a) debugt(b) debugt(c) cout << endl
#define debugIV(a, b, c, d) debugt(a) debugt(b) debugt(c) debugt(d) cout << endl
#else
#define debugI(v)
#define debugII(a, b)
#define debugIII(a, b, c)
#endif


typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
const int INF = 1000000000;
const double EPS = 1e-8;
const int MOD = 100000007;
const int MAXN = 10000000;
const double PI = acos(-1.0);

struct Point
{
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) {};
    inline void read() { scanf("%lf%lf", &x, &y); }
};

template<class T> T sqr(T x) { return x * x; }

inline double dist(Point a, Point b)
{
    return sqr(a.x - b.x) + sqr(a.y - b.y);
}

Point p1[60], p2[60];
int a, b, c, u, v;

inline int belong(Point x)
{
    double dis = 1e20, id, t;
    FE(i, 1, b)
    {
        t = dist(x, p2[i]);
        if (dis > t)
        {
            dis = t;
            id = i;
        }
    }
    return id;
}

int solve(Point a, Point b)
{
    int ia = belong(a), ib = belong(b);
    if (ia == ib) return 0;
    if (dist(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("0.txt", "r", stdin);
    while (~RII(a, b))
    {
        FE(i, 1, a) p1[i].read();
        FE(i, 1, b) p2[i].read();
        RI(c);
        REP(i, c)
        {
            RII(u, v);
            WI(solve(p1[u], p1[v]));
        }
    }
    return 0;
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值