CCF 201912-2 回收站选址
对于这道题,关于坐标为负数时,尝试了却没有解决,所以,先把这个问题发出来,等后面,自己能力强了。再来解决这个问题。还是坚持每天要做题!
#include<iostream>
using namespace std;
int a[1000][1000] = { 0 };
int main()
{
int n;
cin >> n;
int x, y;
int maxx=0, maxy=0;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
a[x][y] = 1;
if (x > maxx) maxx = x;
if (y > maxy) maxy = y;
}
cout << endl;
cout << endl;
int A=0, B=0, C=0, D=0, E = 0;
for(int i=1; i<maxx; i++)
for (int j = 1; j < maxy; j++)
{
if (a[i][j] == 1) {
if(a[i][j+1]==1 && a[i][j-1]==1 &&
a[i-1][j]==1 && a[i+1][j]==1)
{
if (a[i + 1][j + 1] == 1 && a[i - 1][j + 1] == 1 &&
a[i + 1][j - 1] == 1 && a[i - 1][j - 1] == 1)
E++;
else {
if ((a[i + 1][j + 1] == 1 && a[i - 1][j + 1] == 1 &&
a[i + 1][j - 1] == 1) || (a[i - 1][j + 1] == 1 &&
a[i + 1][j - 1] == 1 && a[i - 1][j - 1] == 1) ||
(a[i + 1][j + 1] == 1 && a[i - 1][j + 1] == 1 &&
a[i - 1][j - 1] == 1))
D++;
else {
if ((a[i + 1][j + 1] == 1 && a[i - 1][j + 1] == 1) ||
(a[i - 1][j + 1] == 1 && a[i + 1][j - 1] == 1) ||
(a[i + 1][j - 1] == 1 && a[i - 1][j - 1] == 1) ||
(a[i + 1][j + 1] == 1 && a[i + 1][j - 1] == 1) ||
(a[i + 1][j + 1] == 1 && a[i - 1][j - 1] == 1) ||
(a[i - 1][j + 1] == 1 && a[i - 1][j - 1] == 1))
C++;
else if (a[i + 1][j + 1] == 1 || a[i - 1][j + 1] == 1 ||
a[i + 1][j - 1] == 1 || a[i - 1][j - 1] == 1)
B++;
else A++;
}
}
}
}
}
cout << A << endl;
cout << B << endl;
cout << C << endl;
cout << D << endl;
cout << E << endl;
return 0;
}