题目
代码
#include <bits/stdc++.h>
using namespace std;
const int R = 2e9+1;
typedef long long LL;
unordered_set<LL> s;
int piles[5];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int dx1[4] = {-1, -1, 1, 1}, dy1[4] = {-1, 1, -1, 1};
bool check(LL r)
{
int y = r / R;
int x = r % R;
for(int i = 0; i < 4; i++)
{
LL t = r + dx[i] + dy[i] * R;
if(!s.count(t)) return false;
}
return true;
}
int rate(LL r)
{
int retval = 0;
int y = r / R;
int x = r % R;
for(int i = 0; i < 4; i++)
{
LL t = r + dx1[i] + dy1[i] * R;
if(s.count(t)) retval++;
}
return retval;
}
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
int x, y;
cin >> x >> y;
x += 1e9; y += 1e9;
LL r = 1ll * y * R + x;
s.insert(r);
}
for(auto c : s)
{
if(check(c))
{
piles[rate(c)]++;
}
}
for(int i = 0; i < 5; i++)
{
cout << piles[i] << "\n";
}
return 0;
}
爆int漏掉的可能地方
- 函数返回值
- 函数传参
- 多项和
- 乘积