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

Re:谁能告诉我为什么WA。。郁闷死了。。提供组数据也行啊。。

Posted by 2008161035 at 2010-03-26 23:56:14 on Problem 1573
In Reply To:谁能告诉我为什么WA。。郁闷死了。。提供组数据也行啊。。 Posted by:superszy at 2010-03-26 19:31:02
改动了一下,过了,你自己对比一下吧

#include <iostream>
#include <vector>
using namespace std;

char map[50][50];
bool flag[50][50];

int main()
{
	int x , y , k;
	int step=0 , loop = 0;
	
	cin >> x>> y>>k;

	while (x != 0)
	{
		memset( flag,false,sizeof(flag) );

		for (int x1 =0 ; x1 < x ; x1++)
		{
			for (int y1 = 0; y1 < y ; y1++)
			{
				cin >> map[x1][y1];
			}
		}

		int x2 = 0 , y2 = k-1;

		while ( ( !( x2<0 || y2<0 || x2>=x || y2>=y ) )  && flag[x2][y2] == false)
		{
			flag[x2][y2] = true;
			switch( map[x2][y2] )
			{
			case 'E':
				{
					y2++;
					break;
				}
			case 'W':
				{
					y2--;
					break;
				}
			case 'S':
				{
					x2++;
					break;
				}
			case 'N':
				{
					x2--;
					break;
				}
			default :
				break;
			}
			step++;					
		}

		if ( x2<0 || y2<0 || x2>=x || y2>=y)
		{
             	memset( flag,false,sizeof(flag) );
        }
        else
        {
    		if ( flag[x2][y2] == true )
    		{
    			memset( flag,false,sizeof(flag) );
    			while (flag[x2][y2] == false)
    			{
    				flag[x2][y2] = true;
    				switch( map[x2][y2] )
    				{
    				case 'E':
    					y2++;
    					break;
    				case 'W':
    					y2--;
    					break;
    				case 'S':
    					x2++;
    					break;
    				case 'N':
    					x2--;
    					break;
    				default :
    					break;
    				}
    				loop++;	
    			}
    		}
        }

		if ( loop == 0 )
			printf("%d step(s) to exit\n",step);
		else
		    printf("%d step(s) before a loop of %d step(s)\n",step-loop,loop);

		step = 0;
		loop = 0;

		cin >> x>> y>>k;
	}

	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