HDU 4007 线扫描

/*******************************************************************************
    网络赛水题,线扫描两下就完了,从左至右,从上至下。。。蛋疼的课设+期末考试终于结束了!
*******************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )
#define CLR(x, k) memset((x), (k), sizeof(x))
#define CPY(t, s) memcpy((t), (s), sizeof(s))
#define SC(t, s) static_cast<t>(s)
#define LEN(s) static_cast<int>( strlen((s)) )
#define SZ(s) static_cast<int>( (s).size() )

typedef double LF;
typedef __int64 LL;		//VC
typedef unsigned __int64 ULL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;

typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VF;
typedef vector<string> VS;

template <typename T>
T sqa(const T & x)
{
	return x * x;
}
template <typename T>
T gcd(T a, T b)
{
	if (!a || !b)
	{
		return max(a, b);
	}
	T t;
	while (t = a % b)
	{
		a = b;
		b = t;
	}
	return b;
};

const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffffLL;		//15f
const double oo = 10e9;
const double eps = 10e-7;
const double PI = acos(-1.0);

#define  ONLINE_JUDGE

const int MAXN = 1004;

int n, R;
int tx[MAXN];
struct Node
{
	int x, y;
	int id;
}nd[MAXN], tt[MAXN];

bool cmp_y(const Node & na, const Node & nb)
{
	return na.y < nb.y;
}
void ace()
{
	int xcnt;
	int res;
	while (cin >> n >> R)
	{
		for (int i = 0; i < n; ++i)
		{
			cin >> nd[i].x >> nd[i].y;
			nd[i].id = i;
			tx[i] = nd[i].x;
		}
		sort(nd, nd + n, cmp_y);
		sort(tx, tx + n);
		xcnt = unique_copy(tx, tx + n, tx) - tx;
		res = 0;
		for (int i = 0; i < xcnt; ++i)
		{
			int left = tx[i];
			int right = left + R;
			int ycnt = 0;
			for (int k = 0; k < n; ++k)
			{
				if (left <= nd[k].x && nd[k].x <= right)
				{
					tt[ycnt++] = nd[k];
				}
			}
			if (0 == ycnt)
			{
				continue ;
			}
			int low = 0, high = 0;
			while (low < ycnt && high < ycnt)
			{
				if (tt[high].y - tt[low].y <= R)
				{
					res = max(res, high - low + 1);
					++high;
				}
				else
				{
					++low;
				}
			}
		}
		cout << res << endl;
	}
	return ;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif
	ace();
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值