Rumah > Soal Jawab > teks badan
PHPz2017-04-17 13:43:33
不用谢,已经通过的C++代码:
using namespace std;
int main()
{
int n, m, k, i, j;
//ifstream cin("test.txt");
while (cin>>n>>m)
{
cin >> k;
int max = k;
int x = 0, y = 0, time = 1;
int area[12][12];
memset(area, 0, sizeof(area));
for (i = 0;i < k; i++)
{
cin >> x >> y;
area[x][y] = 1;
}
while(time++)
{
int num = 0;
for (i = 1;i <= n;i++)
{
for (j = 1;j <= m;j++)
{
//为6永远不会感染别人
if (area[i][j] >=1 && area[i][j] <=5)
area[i][j]++; //我靠,程序半天没调出来,这句写成了area[x][y]++; fuck!!!
if (area[i][j] == 4)
{
if (area[i - 1][j] == 0) area[i - 1][j] = 1;
if (area[i + 1][j] == 0) area[i + 1][j] = 1;
if (area[i][j + 1] == 0) area[i][j + 1] = 1;
if (area[i][j - 1] == 0) area[i][j - 1] = 1;
}
}
}
for (i = 1;i <= n; i++)
{
for (j = 1;j <= m;j++)
{
if (area[i][j] >= 1 && area[i][j] <= 5)
num++;
}
}
if (num > max) max = num;
if (num < k) break;
}
cout << max << endl;
}
return 0;
}