試題編號: 201912-2
試題名稱: 回收站選址
時間限制: 1.0s
內存限制: 512.0MB
問題描述:
吐槽
老實說這一題數據真的垃圾,很多人都是用數組直接跑過了,數據強點平均分還可以降個30-40左右。
實現代碼
#include<iostream>
#include<map>
#include<cstring>
using namespace std;
const int maxn = 1e3 + 5;
struct Node{
int x, y;
Node(){}
Node(int a, int b){
x = a, y = b;
}
bool operator < (const Node& other) const{
if(x != other.x) return x < other.x;
else return y < other.y;
}
};
int cnt[5];
int yway[] = {-1,1,0,0};
int xway[] = {0,0,-1,1};
map<Node, int> mp;
bool fun(Node node){
for(int i = 0; i < 4; i++){
int x = node.x + xway[i], y = node.y + yway[i];
if(mp.find(Node(x, y)) == mp.end()) return false;
}
if(mp.count(Node(node.x-1,node.y+1))) mp[node]++;
if(mp.count(Node(node.x-1,node.y-1))) mp[node]++;
if(mp.count(Node(node.x+1,node.y-1))) mp[node]++;
if(mp.count(Node(node.x+1,node.y+1))) mp[node]++;
return true;
}
int main(){
memset(cnt, 0, sizeof(cnt));
int n, x, y;
cin >> n;
while(n--){
cin >> x >> y;
mp[Node(x, y)] = 0;
}
for(map<Node,int>::iterator it = mp.begin(); it != mp.end(); ++it){
if(fun(it->first)) cnt[it->second]++;
}
for(int i = 0; i < 5; i++){
cout << cnt[i] << endl;
}
return 0;
}