4007 Dave(The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest)
2017-07-06 19:41
573 查看
Dave
Problem DescriptionRecently, 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; }
相关文章推荐
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest(套题HDU4001-4010)
- The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest题解
- 【树状数组】The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - G Panda
- 【转】The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest 出题报告
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - G Panda
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&Dave
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - B Eliminate Witches!
- HDU 4064 Carcassonne(插头DP)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
- 【栈+模拟】The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - B Eliminate Witches!
- HDU 4031 Attack(离线+线段树)(The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest)
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - G Panda
- The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest(HDU4021-4030)
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - G Panda
- 4046 Panda(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)
- The 36th ACM/ICPC Asia Regional Dalian Site 1006 Dave
- 4045 Machine scheduling(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)
- HDU4022-map+multiset--The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
- HDU 4069 Squiggly Sudoku(DLX)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
- HDU 4033 4036 4039 The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest