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. the process cannot access the file because it is being used by another process

    当在IIS中改动绑定的port号后启动时遇到例如以下错误,表明你的port号已经被占用了 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdmljMDIyOA ...

  2. JavaScript学习笔记:检测数组方法

    检查数组的方法 很多时候我们需要对JavaScript中数据类型(Function.String.Number.Undefined.Boolean和Object)做判断.在JavaScript中提供了 ...

  3. MySql 跟踪命令

    SHOW ; SHOW FULL PROCESSLIST; ; USE table1; ; SHOW PROFILES; ; SHOW TABLES; SHOW PROFILES; SHOW PROF ...

  4. Sublime Text3 Package Control和Emmet插件安装方法

    因为初学前端,所以今天安装了Sumblime Text 3,然后就停不下来去找Package Control的安装方法. 网络上我找到并尝试过的方法有两种,我使用的是用Python代码去安装并成安装成 ...

  5. GDI+编程的10个基本技巧(转)

    创建绘图表面 创建绘图表面有两种常用的方法.下面设法得到PictureBox的绘图表面. private void Form1_Load(object sender, System.EventArgs ...

  6. C# Serializable学习

    先上代码,感觉这个功能很给力啊. class Program { static void Main(string[] args) { //下面代码将对象Person进行序列化并存储到一个文件中 Per ...

  7. Linux下运行C++程序出现"段错误(核心已转储)"的原因

    今天写程序出现了“段错误(核心已转储)"的问题,查了一下资料,加上自己的实践,总结了以下几个方面的原因. 1.内存访问出错  这类问题的典型代表就是数组越界. 2.非法内存访问 出现这类问题 ...

  8. SharpZipLib 压缩文档下载

    using ICSharpCode.SharpZipLib.Zip; Response.Clear(); Response.ClearContent(); Response.ClearHeaders( ...

  9. Oracle 10g体系结构及安全管理

    (1)               Oracle数据库服务器:数据库,实例 (2)               数据库:(1)物理存储—数据文件,控制文件,日志文件,(2)逻辑存储—表空间,段,区间, ...

  10. [C入门 - 游戏编程系列] 序言篇

    记得学习C语言的时候,看着别人能写各种各样的小游戏和小软件,甚是羡慕.而自己,虽然说语法都会,但是真正上手写个几百行的代码,就显得力不从心.曾经一度很是郁闷,看过一些书,大都处于教语法的层面,有些涉及 ...