HDU4007 Dave 暴力 TWT Tokyo Olympic 2combo-1

Dave

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


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

暴力搜索。。。因为至多只有1000个点O(n^2)是可以接受的

机房的今日才刚刚开始呢,这个键盘敲起来好爽。。

昨晚这题想错了wa到死。。。

这题比较温柔的地方是正方形的边都是和坐标轴平行的,不考虑旋转的情况。。。。

zhangjiatao1说的确实。。。暴力得也有技巧

首先枚举画正方形的左断电的x值,根据题中所给的点来枚举,再在每个点像右拓展r个单位,将这个区域的点全部搞进来,将这些点根据y的值来排个序,再来枚举正方形的下界,依此动态更新max值

感觉就是按照这个图来对坐标区域进行扫描的:


下面代码:


/*
 ━━━━━┒
 ┓┏┓┏┓┃μ'sic foever!!
 ┛┗┛┗┛┃\○/
 ┓┏┓┏┓┃ /
 ┛┗┛┗┛┃ノ)
 ┓┏┓┏┓┃
 ┛┗┛┗┛┃
 ┓┏┓┏┓┃
 ┛┗┛┗┛┃
 ┓┏┓┏┓┃
 ┛┗┛┗┛┃
 ┓┏┓┏┓┃
 ┃┃┃┃┃┃
 ┻┻┻┻┻┻
 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
const long long maxn=1010;
struct unit{
    long long x,y;
}point[maxn];
bool compare(unit a,unit b){
    if(a.x==b.x){
        return a.y<b.y;
    }else{
        return a.x<b.x;
    }
}
int main(){
    int n,i,j;
    long long r;
    while(~scanf("%d%lld",&n,&r)){
        for(i=1;i<=n;i++){
            scanf("%lld%lld",&point[i].x,&point[i].y);
        }
        sort(point+1,point+1+n,compare);
        /*for(i=1;i<=n;i++){
            cout<<point[i].x<<" "<<point[i].y<<endl;
        }*/
        int max_points=0;
        long long left=point[1].x;
        int now=1;
        while(now<=n){ 
            long long x_pro=point[now].x+r;
            long long save_y[maxn];
            int y_n=1;
            for(i=now;point[i].x<=x_pro&&i<=n;i++){
            	save_y[y_n]=point[i].y;
            	y_n++;
			}
			sort(save_y+1,save_y+y_n);
			/*for(i=1;i<y_n;i++){
				cout<<save_y[i]<<" ";
			}
			cout<<endl;*/
			for(i=1;i<y_n;i++){
				int ans=0;
				long long y_pro=save_y[i]+r;
				for(j=i;j<y_n;j++){
					if(save_y[j]<=y_pro){
						//cout<<"test "<<save_y[j]<<" "<<y_pro<<endl;
						ans++;
					}
				}
				max_points=max(max_points,ans);
			}
			for(i=now;point[i].x==left;i++);
            left=point[i].x;
            now=i;
        }
        cout<<max_points<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值