题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5254
题意:
题解:
暴力
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 5e2+10;
int f[maxn][maxn];
int main(){
int T=read();
for(int cas=1; cas<=T; cas++){
MS(f);
int n=read(),m=read();
int g = read();
for(int i=1; i<=g; i++){
int x=read(),y=read();
f[x][y] = 1;
}
while(1){
bool add = false;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(f[i][j]) continue;
if(f[i-1][j] && f[i][j-1] && i>1 && j>1){
f[i][j] = 1;
add = true;
continue;
}
if(f[i-1][j] && f[i][j+1] && i>1 && j<m){
f[i][j] = 1;
add = true;
continue;
}
if(f[i+1][j] && f[i][j-1] && i<n && j>1){
f[i][j] = 1;
add = true;
continue;
}
if(f[i+1][j] && f[i][j+1] && i<n && j<m){
f[i][j] = 1;
add = true;
continue;
}
}
}
if(!add) break;
}
int ans = 0;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
ans += f[i][j];
cout << "Case #" << cas << ":\n" << ans << endl;
}
return 0;
}