/*
n行 m列 t出水管 k分钟
1.接收初始水管位置,并初始化计数器为t
2.将初始水管位置入队及每轮结束标志(0,0)
3.依次出队,按方向循环
3.1判断是否合法,合法则计数器加一且入队,不合法则跳过
3.2直至遇到(0,0)表示一轮结束
4.判断是否达到k轮
补:创建二维数组,查看灌溉状态
*/
#include<iostream>
#include<queue>
using namespace std;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
class Location
{
public:
int x;
int y;
Location()
{
x = 0;
y = 0;
}
Location(int nx,int ny)
{
x = nx;
y = ny;
}
};
int main()
{
int n, m, t, k;
cin >> n >> m >> t;
bool** visit = new bool* [n + 1];
for (int i = 0; i < n + 1; i++)
visit[i] = new bool[m + 1];
//memset(visit, false, sizeof(visit));
for (int i = 0; i < n + 1; i++)
{
for (int j = 0; j < m + 1; j++)
{
visit[i][j] = false;
}
}
int cnt=t;
int nx, ny;
queue<Location> q;
Location sign(0, 0);
for (int i = 0; i < t; i++)
{
cin >> nx >> ny;
Location n(nx, ny);
visit[nx][ny] = true;
q.push(n);
}
cin >> k;
q.push(sign);
for (int i = 0; i < k; i++)
{
while (true)
{
Location temp = q.front();
q.pop();
if (temp.x == 0 && temp.y == 0)
break;
for (int j = 0; j < 4; j++)
{
int tx = temp.x + dx[j];
int ty = temp.y + dy[j];
//cout << "x:" << tx << " y:" << ty;
if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && !visit[tx][ty])
{
//cout << "可行"<<endl;
Location p(tx, ty);
q.push(p);
visit[tx][ty] = true;
cnt++;
}
//else
//cout<<"不可行"<<endl;
}
}
q.push(sign);
}
cout << cnt;
system("pause");
return 0;
}