题目背景
一个恐怖组织在一座城市中安放了定时炸弹,其威力巨大,现在这里的警长想知道最坏的情况下会有多少街区受威胁。
题目描述
在一个城市有N*M个街区,每个街区由坐标描述,如图所示:
行 列 1 2 3 … M
1 (1,1) (1,2) (1,3) … (1,M)
2 (2,1) (2,2) (2,3) … (2,M)
3 (3,1) (3,2) (3,3) … (3,M)
… … … … … …
N (N,1) (N,2) (N,3) … (N,M)
现在已知有一个恐怖组织在其中的一个街区安放了定时炸弹,其威力为T,即所有到这个街区的直线距离小于等于T的街区都会受威胁,已知有K个可能的炸弹安放位置,现在这里的警长想知道最坏的情况下会有多少街区受威胁。
输入格式
第一行四个正整数N,M,K和T
接下来K行每行两个正整数Xi Yi,描述每个可能安放炸弹的街区。
输出格式
一个正整数为在最坏情况下有多少街区会受威胁。
输入输出样例
输入 #1
4 5 3 2
1 2
3 4
4 5
输出 #1
11
说明/提示
对于20%的数据 K=1
对于50%的数据 N,M≤1000 K≤20 T≤100
对于100%的数据 N,M≤100000 K≤50 T≤300
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cstdio>
#include<math.h>
#include<climits>
#include <map>
using namespace std;
int k,n,m,t,ans = 0,maxx,x,y;
double sf(int x1, int y1, int x2, int y2) {
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
ios_base::sync_with_stdio(0); // 让cin变快
cin.tie(0); // 让cin变快
cin >> n >> m >> k >> t ;
while(k--) {
cin >> x >> y;
ans = 0;
for(int i = max(1,x-t); i <= min(n,x+t); i++) {
for(int j = max(1,y-t); j <= min(m,y+t); j++ ) {
ans += (sf(i,j,x,y) <= t );
}
maxx = max(maxx,ans);
}
}
cout << maxx << endl;
return 0;
}