Dave

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 4095    Accepted Submission(s): 1390

Problem Description
Recently,
Dave is boring, so he often walks around. He finds that
some places are too crowded, for example, the ground. He couldn't
help to think of the disasters happening recently. Crowded place is not
safe. He knows there are N (1<=N<=1000) people on the ground. Now
he wants to know how many people will be in a square with the length of R
(1<=R<=1000000000). (Including boundary).
 
Input
The
input contains several cases. For each case there are two positive
integers N and R, and then N lines follow. Each gives the (x, y)
(1<=x, y<=1000000000) coordinates of people.
 
Output
Output the largest number of people in a square with the length of R.
 
Sample Input
3 2
1 1
2 2
3 3
Sample Output
3
HITE If two people stand in one place, they are embracing.
 
结构体离散化,先对横坐标排序,选定一个横坐标x作为初始值,x+R作为结束值,接下来的点凡是在这个范围内的,把点的纵坐标作为x值存到另一个结构体中y所对应的结构体的y值存为1,找到这里时直接加y值,将y+R-1所对应的结构体的y值标为-1,查找到这里是,说明,已超出了初始y值所能达到的最大边界,减去的即是初始y所对应得点
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int n,R;
struct Node
{
int x;
int y;
}node[],pos[];
bool cmp(Node a,Node b)
{
return a.x<b.x;
}
int main()
{
while(scanf("%d%d",&n,&R)!=EOF)
{
int ans=,cnt=,inf=,start,end,tot=;
for(int i=;i<n;i++)
{
scanf("%d%d",&node[i].x,&node[i].y);
}
sort(node,node+n,cmp);
for(int i=;i<n;i++)
{
tot=;
start=node[i].x,end=node[i].x+R;
for(int j=i;j<n;j++)
{
if(node[j].x>=start && node[j].x<=end)
{
pos[tot].x=node[j].y;
pos[tot++].y=;
pos[tot].x=node[j].y+R+;
pos[tot++].y=-;
}
}
sort(pos,pos+tot,cmp);
for(int j=;j<tot;j++)
{
cnt+=pos[j].y;
inf=max(inf,cnt);
}
ans=max(inf,ans);
}
printf("%d\n",ans);
}
return ;
}

HDU 4007 Dave(离散化)的更多相关文章

  1. hdu 4007 Dave(线性探查+枚举)

    Problem Description Recently, Dave is boring, so he often walks around. He finds that some places ar ...

  2. hdu 4007 Dave (2011年大连ACM网络赛)

    题意:给定正方形的边长 r ,在平面内寻找正方形可以圈住的点的最大的个数. 分析:先对点排序,然后固定一条边,再平移另一条垂直边,得到点的个数,最后比较大小即可. 注意:不包含正方形倾斜的情况! // ...

  3. HDU - 1255 扫描线+离散化进阶

    这道题最开始我以为和HDU - 1542 那道题一样,只需要把cover次数改成2次即可,但是后面仔细一想,我们需要求的是覆盖次数大于等于2次的,这样的话,我们需要维护两个长度,HDU-1542 由于 ...

  4. HDU 5925 Coconuts 离散化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5925 Coconuts Time Limit: 9000/4500 MS (Java/Others) ...

  5. hdu 5303 DP(离散化,环形)+贪心

    题目无法正常粘贴,地址:http://acm.hdu.edu.cn/showproblem.php?pid=5303 大意是给出一个环形公路,和它的长度,给出若干颗果树的位置以及树上的果子个数. 起点 ...

  6. HDU 1711 kmp+离散化

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/Other ...

  7. 2019 年百度之星·程序设计大赛 - 初赛一 C. HDU 6670 Mindis 离散化+dijkstra

    题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6670 Mindis Time Limit: 4000/2000 MS (Java/Others) M ...

  8. HDU 5862(离散化+树状数组)

    Problem Counting Intersections 题目大意 给定n条水平或竖直的线段,统计所有线段的交点个数. (n<=100000) 解题分析 首先将线段离散化. 然后将所有线段按 ...

  9. Hdu 1856(离散化+并查集)More is better

    题意:一些人遵循朋友的朋友也是朋友原则,现在找出最大的朋友圈, 因为人的编号比较大,但是输入的数据最多是10w行,所以可得出最多也就20w人,所以可以进行一下离散化处理,这样数据就会毫无压力 //// ...

随机推荐

  1. php时间戳转化成时间相差8小时问题

    php时间戳 转化成时间的时候 $mytime=time(); echo $mytime.'<br />'; echo date('Y-m-d H:i:s',$mytime); 会产生8个 ...

  2. 排序算法(Apex 语言)

    /* Code function : 冒泡排序算法 冒泡排序的优点:每进行一趟排序,就会少比较一次,因为每进行一趟排序都会找出一个较大值 时间复杂度:O(n*n) 空间复杂度:1 */ List< ...

  3. Debian9.5 系统配置NFS配置说明

    NFS是Network File System的缩写,即网络文件系统.它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户端可以通过挂载(mount)的方式将NFS ...

  4. CentOS6.9下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数

    密钥登录步骤(免密码登录)ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,出于安全方面的考虑,介绍密钥认证方式登录到linux/unix的方 ...

  5. 包及常用模块(time、datetime、random、sys)

    什么是包?‘ #官网解释 Packages are a way of structuring Python’s module namespace by using “dotted module nam ...

  6. java 线程传参 方式

    第一类:主动向线程传参   public class ThreadTest extends Thread { public ThreadTest() { } /** * 第一种通过构造方法来传递参数 ...

  7. HDU 4406 GPA

    GPA Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 440664 ...

  8. C# 从需要登录的网站上抓取数据

    [转] C# 从需要登录的网站上抓取数据 背景:昨天一个学金融的同学让我帮她从一个网站上抓取数据,然后导出到excel,粗略看了下有1000+条记录,人工统计的话确实不可能.虽说不会,但作为一个学计算 ...

  9. MapReduce JOB 的输出与输出笔记。

    提高 MapReduce 价值,自定义输入和输出. 比如跳过存储到 HDFS 中这个耗时的布置. 而只是从原始数据源接受数据,或者直接将数据发送给某些处理程序. 这些处理程序在 MapReduce 作 ...

  10. 四 HBase 客户端设置缓存优化查询。

    其实查询无非是一个 HBase 的 RPC 计算公式 .然后给API 提供值. RPCs = (Rows * Cols per Row) / Min(Cols per Row, Batch Size) ...