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 = ;
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 = ; i < N; i++){
scanf("%d%d", &dt[i].x, &dt[i].y);
}
sort(dt, dt + N);
int ans = ;
for(int i = ; i < N; i++){
int tp = ;
p[tp++] = dt[i].y;
for(int j = i + ; j < N; j++){
if(dt[j].x - dt[i].x > R)
break;
p[tp++] = dt[j].y;
}
sort(p, p + tp);
for(int l = ; l < tp; l++){
int cnt = upper_bound(p + l, p + tp, p[l] + R) - (p + l);
ans = max(ans, cnt);
}
}
printf("%d\n", ans);
}
return ;
}

Dave(正方形能围成的最大点数)的更多相关文章

  1. Agent J(求三个圆围成的区域面积)

    A - A Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  2. LeetCode 85 | 如何从矩阵当中找到数字围成的最大矩形的面积?

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题53篇文章,我们一起来看看LeetCode中的85题,Maximal Rectangle(最大面积矩形). 今天的 ...

  3. 求曲线y=lnx在区间(2,6)内的一条切线,使得该切线与直线x=2,x=6及曲线y=lnx所围成的图形的面积最小。

    求曲线y=lnx在区间(2,6)内的一条切线,使得该切线与直线x=2,x=6及曲线y=lnx所围成的图形的面积最小. 1.先画图. 2.设切点为(a,lna) (2<a<6) 3.切线方程 ...

  4. 多个n维向量围成的n维体积的大小

    前言 上周我们数学老师给了我们一道题,大意就是两个向量a和b,一个点M=$x*a+y*b$,x,y有范围,然后所有M组成的面积是一个定值,求x+y的最小值.当然这是道小水题,但我在想,如果把两个向量变 ...

  5. uva11178 Morley’s Theorem(求三角形的角三分线围成三角形的点)

    Morley’s Theorem Input: Standard Input Output: Standard Output Morley’s theorem states that that the ...

  6. 微信小程序canvas把正方形图片绘制成圆形

    wxml代码: <view class="result-page"> <canvas canvas-id='firstCanvas' style='width:1 ...

  7. n阶方阵,数字从1~n^2,顺时针增大

    运行结果如下图: 解题思路:可以将这个问题分解成x个外围正方形所围成的图形,外围的正方形又可以分为4个步骤,向右依次增大.向下依次增大.向左依次增大.向上依次增大.基本思路就是如此,最关键的就是什么时 ...

  8. HDU 4739 求正方形个数

    九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711707 求所有可能围成的正方形,借个代码 #include <que ...

  9. 用初中代数结合python画出正方形

    在屏幕上打印类似下面的图形: 常规画正方形的算法: 这几乎是初学所有计算机语言时都会遇到的问题.算法都大致类似,就是找出打印规律然后用计算机语句表达出来.最常规的算法是:输入数字n就打印n行,首行和尾 ...

随机推荐

  1. [Angular 2] Using events and refs

    This lesson shows you how set listen for click events using the (click) syntax. It also covers getti ...

  2. [Redux] Extracting Container Components -- Complete

    Clean TodoApp Component, it doesn't need to receive any props from the top level component: const To ...

  3. 图像重采样(CPU和GPU)

    1 前言 之前在写影像融合算法的时候,免不了要实现将多光谱影像重采样到全色大小.当时为了不影响融合算法整体开发进度,其中重采样功能用的是GDAL开源库中的Warp接口实现的. 后来发现GDAL War ...

  4. [转载]aptitude与apt-get的区别和联系

    转自 http://www.cnblogs.com/yuxc/archive/2012/08/02/2620003.html 命令 下面将要介绍的所有命令都需要sudo!使用时请将“packagena ...

  5. T4文本模板

    <#...#> 可以包含语句 <#=...#>  用于表达式,提供“输出”操作 <#+ ...> 使用类功能控制块向文本模板添加方法.属性.字段,必须作为文件中最后 ...

  6. Android -------- API等级

      API等级 Android版本 代号名称(基本上是按ABC命名排序的) 注释说明 1 Android 1.0     2 Android 1.1 Petit Four   3 Android 1. ...

  7. ADO.Net总结

    ADO.NET简介 一.    ADO.NET的组成(ADO.NET是什么?能干什么)客户体验      ADO.NET就是一组类库可以让我们通过程序的方式访问数据库 ADO.NET主要包括5个对象, ...

  8. 那些容易忽略的事4-(正则表达式反向引用\n)

    n 是一个正整数.一个反向引用(back reference),指向正则表达式中第 n 个括号(从左开始数)中匹配的子字符串. ps1:从左开始数,从左到优,也是从外到里,依次是\1,\2,\3... ...

  9. 流输入练习——寻找Sb.VI codevs 3096

    题目描述 Description 已知某开放授权人员名叫Serb,由于经常修改各种数据,因此开发人员们都喊他SB.现在他和许多人一起过飞机安检,排成了一长队列,请问SB.是否在队列中. 输入描述 In ...

  10. (原).cc 和 .cpp 后缀结尾的文件的区别

    This caused a few problems the first time C++ was ported to a system where case wasn't significant i ...