Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

难道这题就不能用皮克定理做?

Posted by suncongbo at 2017-02-14 18:52:56 on Problem 4022
///WA

#include<cstdio>
#include<cstring>
using namespace std;

char a[104][104];
bool f[104][104];
int n,m,ans,cnt;
int area;

void dfs(int x,int y)
{
	f[x][y] = true;
	ans++;
	
	if(x-1 >= 0 && f[x-1][y] == false)
	{
		dfs(x-1,y);
	}
	if(x+1 <= n+2 && f[x+1][y] == false)
	{
		dfs(x+1,y); 
	}
	if(y-1 >= 0 && f[x][y-1] == false)
	{
		dfs(x,y-1);
	}
	if(y+1 <= m+2 && f[x][y+1] == false)
	{
		dfs(x,y+1);
	}
}

void reset()
{
	memset(f,false,sizeof(f));
	area = 0;
	ans = cnt = 0;
}

int main()
{
	int i,j,sx,sy;
	char ch;
	bool flag;
	
	while(scanf("%d%d",&n,&m) != EOF)
	{
		reset();
		
		getchar();
		for(i=1; i<=n; i++)
		{
			for(j=1; j<=m; j++)
			{
				scanf("%c",&a[i][j]);
				if(a[i][j] == '/')
				{
					area++;
					cnt++;
					f[i][j+1] = f[i+1][j] = true;
				}
				else if(a[i][j] == '\\')
				{
					area++;
					cnt++;
					f[i][j] = f[i+1][j+1] = true;
				}
			}
			ch = getchar();
			while(ch != '\n')	ch = getchar();
		}
	
		dfs(0,0);
		area+=2*((n+3)*(m+3)-cnt-ans);
		area-=2;
		area/=2;
		
		printf("%d\n",(int)area);
	}
	
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator