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

Posted by alex900420 at 2009-04-13 22:52:55 on Problem 1763
#include <iostream>
#include <cstdlib>
#define SIZE 250005
using namespace std;

struct coordinate
{
	int x, y;
} coord[SIZE];

struct queue
{
	int d, b, e;
	char direction;
} que[SIZE];

int Comp(const void *p1,const void *p2)
{
	struct queue  *x = (queue *)p1;
	struct queue *y = (queue *)p2;

	if (x->d != y->d)
	{
		return x->d - y->d;
	}
	else
	{
		if (x->b != y->b)
		{
			return x->b - y->b;
		}
		else
		{
			return y->e - x->e;
		}
	}
}

int main()
{
	int n, i, j, k;
	char c;

	scanf("%d", &n);
	getchar();
	coord[0].x = 0;
	coord[0].y = 0;
	for (i = 1; i <= n; i++)
	{
		scanf("%c", &c);
		switch (c)
		{
			case 'N':
				coord[i].x = coord[i - 1].x;
				coord[i].y = coord[i - 1].y + 1;
				break;
			case 'S':
				coord[i].x = coord[i - 1].x;
				coord[i].y = coord[i - 1].y - 1;
				break;
			case 'W':
				coord[i].x = coord[i - 1].x - 1;
				coord[i].y = coord[i - 1].y;
				break;
			case 'E':
				coord[i].x = coord[i - 1].x + 1;
				coord[i].y = coord[i - 1].y;
				break;
		}
	}
	//Computer the distance
	k = 0;
	for (i = 0; i <= n; i++)
	{
		for (j = i + 1; j <= n; j++)
		{
			//N and S
			if (coord[j].x == coord[i].x)
			{
				//N
				if ((coord[j].y > coord[i].y) && ((coord[j].y - coord[i].y) < (j - i)))
				{
					que[k].d = coord[j].y - coord[i].y;
					que[k].b = i;
					que[k].e = j;
					que[k++].direction = 'N';
				}
				//S
				if ((coord[j].y < coord[i].y) && ((coord[i].y - coord[j].y) < (j - i)))
				{
					que[k].d = coord[i].y - coord[j].y;
					que[k].b = i;
					que[k].e = j;
					que[k++].direction = 'S';
				}
			}

			//W and E
			if (coord[j].y == coord[i].y)
			{
				//E
				if ((coord[j].x > coord[i].x) && ((coord[j].x - coord[i].x) < (j - i)))
				{
					que[k].d = coord[j].x - coord[i].x;
					que[k].b = i;
					que[k].e = j;
					que[k++].direction = 'E';
				}
				//W
				if ((coord[j].x < coord[i].x) && ((coord[i].x - coord[j].x) < (j - i)))
				{
					que[k].d = coord[i].x - coord[j].x;
					que[k].b = i;
					que[k].e = j;
					que[k++].direction = 'W';
				}
			}
		}
	}

	//Sort
	qsort(que, k, sizeof(que[0]), Comp);

	//Output
	printf("%d %d %d %c\n", que[0].d, que[0].b, que[0].e, que[0].direction);

	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