| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
mark 。。#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int dd[8][2]={-1,1,-1,0,-1,-1,0,-1,0,1,1,1,1,0,1,-1};
int kk[4][2]={0,1,0,-1,1,0,-1,0};
int r,c,x,y,aa[21][21],total=0;
bool check(int i,int j)
{
if(i>=0&&i<r&&j>=0&&j<c)
return 1;
return 0;
}
void search(int i,int j)
{
aa[i][j]=-1; //mark for visited
int sum=0,newi,newj;
for(int k=0;k<4;k++){
newi=i+kk[k][0];
newj=j+kk[k][1];
if(check(newi,newj)&&aa[newi][newj]==-1)
sum++;}
total+=4-2*sum;
// cout<<sum<<" "<<i<<" "<<j<<endl;
for(int k=0;k<8;k++)
{
newi=i+dd[k][0];
newj=j+dd[k][1];
if(check(newi,newj))
{
if(aa[newi][newj]==1)
{
search(newi,newj);
}
}
}
}
int main()
{
// ifstream cin("0.txt");
int i,j;string s;
while(cin>>r>>c>>x>>y)
{
if(r==0&&c==0&&x==0&&y==0)
break;
total=0;
for(i=0;i<r;i++)
{
cin>>s;
for(j=0;j<c;j++)
{
if(s[j]=='X')
aa[i][j]=1;
else aa[i][j]=0;
}
}
search(x-1,y-1);
cout<<total<<endl;
}
//system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator