4007 Dave(The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest)
来源:互联网 发布:酷友网络 编辑:程序博客网 时间:2024/05/12 15:50
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 (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
一共只有1000个点,先依次将其中的一个点作为标准点与其他点比较,如果两个点的范围在r之间就放入x数组中,然后再比较x数组中有几个点的范围在r之间,取最大值就行
#include<bits/stdc++.h>using namespace std;using LL =int64_t;struct Node { LL x,y;}E[1005];LL x[1005],y[1005];int main(){ ios::sync_with_stdio(0); cin.tie(0); LL n,r; while(cin>>n>>r) { for(int i=0;i<n;i++) cin>>E[i].x>>E[i].y; for(int i=0;i<n;i++) y[i]=E[i].y; sort(y,y+n); int cnt=0,temp; for(int i=0;i<n;i++) { temp=0; for(int j=0;j<n;j++) if(E[j].y<=y[i]+r&&E[j].y>=y[i]) x[temp++]=E[j].x; sort(x,x+temp); int ans=0; x[temp++]=2e9; for(int j=0;j<temp-1;j++) { while(x[ans]<=x[j]+r) ans++; cnt=max(cnt,ans-j); } } cout<<cnt<<endl; } return 0;}
- 4007 Dave(The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest)
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&Dave
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest Find the maximum
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4001
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4002
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4007
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&The kth great number
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&The Frog's Games
- 2011 大连网络赛 The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest 解题报告
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&To Miss Our Children Time
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest(套题HDU4001-4010)
- The 36th ACM/ICPC Asia Regional Dalian Site 1006 Dave
- HDU4021 24 Puzzle The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
- HDU4023 Game The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
- HDU 4034 Graph The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest
- HDU 4038 Stone The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest
- 【转】The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest 出题报告
- [HDU个人排位赛二 1006] Hmz 的女装 【DP】
- JavaWeb学习总结(二十四)——jsp传统标签开发
- tcp_input()函数分析
- 单片机时钟程序(11)timing.h
- CentOS PHP5安装pdo_mysql,openssl,curl扩展
- 4007 Dave(The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest)
- Hadoop问题之mapreduce运行时异常
- JMS之activeMQ安装
- Android笔记---常用控件以及用法
- C++基础知识 课堂复习
- JAVA学习札记04
- boost.asio防止恶意空连接的方法
- k数和 II-LintCode
- LR日期的参数化格式表