博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4007 线扫描
阅读量:2442 次
发布时间:2019-05-10

本文共 2169 字,大约阅读时间需要 7 分钟。

/*******************************************************************************    网络赛水题,线扫描两下就完了,从左至右,从上至下。。。蛋疼的课设+期末考试终于结束了!*******************************************************************************/#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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
(s)#define LEN(s) static_cast
( strlen((s)) )#define SZ(s) static_cast
( (s).size() )typedef double LF;typedef __int64 LL; //VCtypedef unsigned __int64 ULL;typedef pair
PII;typedef pair
PLL;typedef pair
PDD;typedef vector
VI;typedef vector
VC;typedef vector
VF;typedef vector
VS;template
T sqa(const T & x){ return x * x;}template
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; //15fconst double oo = 10e9;const double eps = 10e-7;const double PI = acos(-1.0);#define ONLINE_JUDGEconst 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;}

转载地址:http://yibqb.baihongyu.com/

你可能感兴趣的文章
PostgreSQL 源码解读(48)- 查询语句#33(query_planner函数#9)
查看>>
PostgreSQL 源码解读(47)- 查询语句#32(query_planner函数#8)
查看>>
PostgreSQL 源码解读(17)- 查询语句#2(查询优化基础)
查看>>
FreeBSD安装文件系统(转)
查看>>
最简单FreeBSD网关方案(转)
查看>>
Windows 98 多用户的管理(转)
查看>>
更改Windows XP 的日期和时间(转)
查看>>
windows2000中的“秘密武器”(三)(转)
查看>>
Linux程序应用开发环境和工具经验谈(转)
查看>>
循序渐进教你LINUX之软件配置方法(转)
查看>>
NetBSD 指导手册(转)
查看>>
打造FreeBSD桌面系统(2)(转)
查看>>
Windows 98 注册表大修改(转)
查看>>
Windows 98 给回收站右键菜单增加重命名命令(转)
查看>>
自行添加欢迎对话框中的文本(转)
查看>>
Win2K Terminal Service使用经验(转)
查看>>
Windows 98 注册表应用的30个实例(转)
查看>>
为 Windows 98 的注册表数据库减肥(转)
查看>>
Windows Vista 内建管理员帐号被禁用(转)
查看>>
Geforce 4 MX 440强制Vista 开启玻璃效果(转)
查看>>