| 比赛 | 
    noip20081103 | 
    评测结果 | 
    WWAWAAWWWA | 
    | 题目名称 | 
    花园栅栏 | 
    最终得分 | 
    40 | 
    | 用户昵称 | 
    zqzas | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2008-11-04 08:35:44 | 
显示代码纯文本
#include <iostream>
#define MAXN 111
using namespace std;
const int n=100;
const int Dir[5][2]={{0,0},{0,1},{0,-1},{1,0},{-1,0}};
int X0,Y0,z,now,ans,flag,visit[MAXN][MAXN],noway[MAXN][MAXN][8];
void floodfill(int x,int y)
{
	int a,b;
	for (int dir=1;dir<=4;dir++)
	{
		a=x+Dir[dir][0];
		b=y+Dir[dir][1];
		if (a>=0 && a<=n+1 && b>=0 && b<=n+1)
			if (noway[x][y][dir]!=1 && visit[a][b]==0)
			{
				visit[a][b]=1;
				now++;
				floodfill(a,b);
			}
	}
	
}
void run()
{
	now=1;
	visit[n+1][n+1]=1;
	floodfill(n+1,n+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (visit[i][j]==0)
			{
				ans++;
			}
}
void takestep(int dir,int step)
{
	int x=X0,y=Y0;
	for (int i=1;i<=step;i++)
	{
		if (dir==1)
		{
			noway[x][y][4]=1;
			if (x-1>=0)
				noway[x-1][y][3]=1;
		}			
		if (dir==2)
		{
			if (y-1>=0)
				noway[x][y-1][4]=1;
			if (x-1>=0 && y-1>=0)
				noway[x-1][y-1][3]=1;
		}
		if (dir==3)
		{
			noway[x][y][2]=1;
			if (y-1>=0)
				noway[x][y-1][1]=1;
		}
		if (dir==4)
		{
			if (x-1>=0)
				noway[x-1][y][2]=1;
			if (x-1>=0 && y-1>=0)
				noway[x-1][y-1][1]=1;
		}
		x+=Dir[dir][0];
		y+=Dir[dir][1];
		//visit[x][y]=1;
	}
	X0=x;
	Y0=y;
}
void ini()
{
	int i,step;
	char c;
	cin>>X0>>Y0>>z;
	X0++;Y0++;
	for (i=1;i<=z;i++)
	{
		cin>>c>>step;
		if (c=='N')
			takestep(1,step);
		if (c=='S')
			takestep(2,step);
		if (c=='E')
			takestep(3,step);
		if (c=='W')
			takestep(4,step);
	}
}
int main()
{
	freopen("fence.in","r",stdin);
	freopen("fence.out","w",stdout);
	ini();
	run();
	cout<<ans;
	return 0;
}