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. Linux Putty 复制粘贴

    从putty复制:    用左键选中文字,再其他地方点中键就可以粘贴了,不需要右键粘贴. 在putty中粘贴:    在其他地方用左键选中文字,不用右键复制,保持选中文字高亮,然后在putty中点中键 ...

  2. 最小生成树(MST) prim() 算法 kruskal()算法 A - 还是畅通工程

    某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离. 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公 ...

  3. [LNOI2014]LCA 树链剖分 离线 前缀和 思维题

    题目描述:给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1. 设dep[i]表示点i的深度,LCA(i,j)表示i与j的最近公共祖先. 有q次询问,每 ...

  4. TP5 安装

    一.官方手册: https://www.kancloud.cn/manual/thinkphp5/118003 二.Git 方式安装[最新框架下载方式] 首先克隆下载应用项目仓库 git clone ...

  5. docker切换默认镜像源

    docker切换默认镜像源   基于 debian8 默认安装的 docker 镜像源是在国外,pull 镜像的时候奇慢无比,需要自己手动切换成国内的镜像源. 1. 修改配置文件 docker 默认的 ...

  6. 紫书 例题 10-27 UVa 10214(欧拉函数)

    只看一个象限简化问题,最后答案乘4+4 象限里面枚举x, 在当前这条固定的平行于y轴的直线中 分成长度为x的一段段.符合题目要求的点gcd(x,y) = 1 那么第一段1<= y <= x ...

  7. Java基础学习总结(17)——线程

    一.线程的基本概念 线程理解:线程是一个程序里面不同的执行路径 每一个分支都叫做一个线程,main()叫做主分支,也叫主线程. 程只是一个静态的概念,机器上的一个.class文件,机器上的一个.exe ...

  8. Spring-statemachine Action不能并发执行的问题

    Spring-statemachine版本:当前最新的1.2.3.RELEASE版本 这几天一直被Action是串行执行搞得很郁闷,写了一个demo专门用来测试: public static void ...

  9. struts2.x + Tiles2.x读取多个xml 配置文件

    在web.xml中配置如下即可: <context-param> <param-name>org.apache.tiles.impl.BasicTilesContainer.D ...

  10. 对spring默认的单列模式的理解

    我想大部分朋友对spring的单例模式都比較了解. 什么叫单例模式呢,顾名思义就是无论有多少个请求,都仅仅生成一个实例. 比方在spring中a,b请求都在调用同样的bean ,他们都是调用的同一个b ...