HDU 4007 Dave(离散化)

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[1005],pos[1005];
bool cmp(Node a,Node b)
{
    return a.x<b.x;
}
int main()
{
    while(scanf("%d%d",&n,&R)!=EOF)
    {
        int ans=0,cnt=0,inf=0,start,end,tot=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&node[i].x,&node[i].y);
        }
        sort(node,node+n,cmp);
        for(int i=0;i<n;i++)
        {
            tot=0;
            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=1;
                    pos[tot].x=node[j].y+R+1;
                    pos[tot++].y=-1;
                }
            }
            sort(pos,pos+tot,cmp);
            for(int j=0;j<tot;j++)
            {
                cnt+=pos[j].y;
                inf=max(inf,cnt);
            }
            ans=max(inf,ans);
        }
        printf("%d\n",ans);
    }
    return 0;
}
时间: 2024-10-24 01:50:14

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

HDU 4007 Dave (基本算法-水题)

Dave 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

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

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

hdu 5303 DP(离散化,环形)

题目无法正常粘贴,地址:http://acm.hdu.edu.cn/showproblem.php?pid=5303 大意是给出一个环形公路,和它的长度,给出若干颗果树的位置以及树上的果子个数. 起点为0,背包大小为K,求最小走多少距离能摘完所有的果子并回到起点. 观察得知,公路长度L虽然上界10^9,但果子总和最多10^5,还是可做的. 显然如果想回家时在左半边肯定逆时针返回更近,在右边同理顺时针更近. 所有最优解可能是有饶了一整圈的路或是只在左/右两边往返得到. 由于背包的大小限制每次取果子

HDU 1711 kmp+离散化

http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 30591    Accepted Submission(s): 12870 Problem Description Given two sequences of

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

这道题最开始我以为和HDU - 1542 那道题一样,只需要把cover次数改成2次即可,但是后面仔细一想,我们需要求的是覆盖次数大于等于2次的,这样的话,我们需要维护两个长度,HDU-1542 由于求的是覆盖次数大于等于一次的,我们只需要维护一个覆盖次数大于等于1的长度的len1就行,但是这道题我们要求的是覆盖两次以及两次以上的长度,这样乘以高度差,才是面积. 现在我们来想如何维护这个值? 给线段树打个标记cover,代表这个区间被完全覆盖的次数. 我们先来看看,维护覆盖一次及其以上的,应该怎

[ An Ac a Day ^_^ ] hdu 5925 Coconuts 离散化+BFS求连通块

东北赛根本就没看懂的的题目…… 也用到了离散化 1e9的x y范围 200个坏点 很典型的离散化数据范围 还是不太为什么离散化的遍历下标都要从1开始…… 所以说只做这道题对离散化的理解还不是很深刻…… 因为可能换一道题又不会了 还是要多做啊 1 #include<bits/stdc++.h> 2 #define cl(a,b) memset(a,b,sizeof(a)) 3 #define debug(x) cerr<<#x<<"=="<<

hdu 1864 实数离散化+动态规划+滚动数组

#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <stack> #include <set> #include <map> #include <vector> using namespace st

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

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

hdu 4022 Bombing (离散化)

Bombing Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 3176    Accepted Submission(s): 1195 Problem Description It’s a cruel war which killed millions of people and ruined series of cities. In