zoukankan      html  css  js  c++  java
  • Dave(正方形能围成的最大点数)

    Dave

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


    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
    Hint
    If two people stand in one place, they are embracing.
     
    Source
     
    题解:这个题是要求正方形与坐标轴平行;可以先确定对于x满足的点数,再找y;可以二分找;
    代码:
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<vector>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const int MAXN = 1010;
    typedef long long LL;
    struct Point{
        int x, y;
        friend bool operator < (Point a, Point b){
            return a.x < b.x;
        }
    };
    Point dt[MAXN];
    int p[MAXN];
    int main(){
        int N, R;
        while(~scanf("%d%d", &N, &R)){
            for(int i = 0; i < N; i++){
                scanf("%d%d", &dt[i].x, &dt[i].y);
            }
            sort(dt, dt + N);
            int ans = 0;
            for(int i = 0; i < N; i++){
                int tp = 0;
                p[tp++] = dt[i].y;
                for(int j = i + 1; j < N; j++){
                    if(dt[j].x - dt[i].x > R)
                        break;
                    p[tp++] = dt[j].y;
                }
                sort(p, p + tp);
                for(int l = 0; l < tp; l++){
                    int cnt = upper_bound(p + l, p + tp, p[l] + R) - (p + l);
                    ans = max(ans, cnt);
                }
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    打包时内容过多,node 报错:内存溢出 javascript heap out of memory
    css样式-旋转rotate
    移动端相关事件
    input文本框的事件
    vue项目在IE11下报错Promise未定义
    解疑常用
    table-layout
    7.24 每日学习作业总结概括
    7.23 每日学习作业总结
    控制流程之while循环
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5523985.html
Copyright © 2011-2022 走看看