T1,T2较简单就不发了
T3 思维题,一个格子只被覆盖一次时,覆盖它的基站一定选,因为网格很大,用map离散化
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define lowbit(x)x & (-x)
const int N = 1e4 + 10, mod = 1e9 + 7,inf = 1e9;
map<int, map<int, int>>g;
vector<pair<int, int>> dic = {{0,0},{0,-1},{0,1},{1,0},{1,1},{1,-1},{-1,0},{-1,-1},{-1,1}};
int x[N],y[N];
void solve(){
int n, ans = 0,cnt = 0;
cin >> n;
for(int i = 1; i<= n; ++i){
cin >>x[i] >>y[i];
for(auto [dx, dy] : dic){
dx += x[i];
dy += y[i];
g[dx][dy]++;
if(dx >= 0 && dy >= 0 && dx < 10000 && dy < 10000 && g[dx][dy] == 1){
ans++;
}
}
}
for(int i = 1; i <= n; ++i){
bool flag = false;
for(auto [dx, dy] : dic){
dx += x[i];
dy += y[i];
if(dx >= 0 && dy >= 0 && dx < 10000 && dy < 10000 && g[dx][dy] == 1){
flag = true;
}
}
cnt += flag;
}
cout << cnt << " "<< ans << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while(t--){
solve();
}
return 0;
}
只过了 95%,可能是边界问题?不懂
#笔试##华为#