CCF201912-2 回收站选址

代码长度 1.610KB
编程语言 C0X
评测结果 正确
得分 100
时间使用 15ms
空间使用 748.0KB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;

set<pair<int, int>> p;
vector<int> cnt(5);
set<pair<int, int>> pre;

int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int minx = 100000, miny = 100000;
int maxx = -1, maxy = -1;
while (n--) {
int xi, yi;
cin >> xi >> yi;
p.emplace(xi, yi);
pre.emplace(xi, yi);
pre.emplace(xi-1, yi);
pre.emplace(xi+1, yi);
pre.emplace(xi, yi-1);
pre.emplace(xi, yi+1);
if (xi < minx) {
minx = xi;
}
if (xi > maxx) {
maxx = xi;
}
if (yi < miny) {
miny = yi;
}
if (yi > maxy) {
maxy = yi;
}
}
for (auto xp : pre) {
int &xx = xp.first;
int &yy = xp.second;
if (p.count({xx, yy})
&& p.count({xx, yy - 1})
&& p.count({xx, yy + 1})
&& p.count({xx - 1, yy})
&& p.count({xx + 1, yy})
) {
int score = 0;
if (p.count({xx - 1, yy - 1})) {
++score;
}
if (p.count({xx - 1, yy + 1})) {
++score;
}
if (p.count({xx + 1, yy - 1})) {
++score;
}
if (p.count({xx + 1, yy + 1})) {
++score;
}
++cnt[score];
}
}
cout << cnt[0] << endl
<< cnt[1] << endl
<< cnt[2] << endl
<< cnt[3] << endl
<< cnt[4] << endl;
}
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

请我喝杯咖啡吧~

支付宝
微信