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

老是WA。麻烦大家帮忙看看。我的思路是机器人总是选择距离它最近的G。

Posted by monkeyfu at 2003-11-11 12:50:59 on Problem 1548
#include<iostream>
#define MAX 25

using namespace std;

struct POINT
{
	int x, y;
	int d;
};

int map[MAX][MAX];
int sum;



int slove(int x, int y)
{
	int i, j;
	int n;
	int flag;
	struct POINT pt[MAX*MAX];
	int min;
	int tx, ty;

	map[x][y] = 0;
	n = 0;
	flag = 0;



	for(i = x;i < MAX;i++)
	{
		for(j = y;j < MAX;j++)
		{
			if(map[i][j] == 1)
			{
				pt[n].x = i;
				pt[n].y = j;
				pt[n].d = i*i + j*j;
				n++;
/*
				cout << "x = " << x << "y = " << y << "\n";
				cout << "px = " << i << "py = " << j << "d = " << x*x + y*y << '\n';
*/
				flag = 1;
			}
		}
	}

	if(flag == 0)
	{
		sum++;
		return 0;
	}

	


	min= MAX * MAX + MAX * MAX + 1;

	tx = x;
	ty = y;

	while(n--)
	{
		if(pt[n].d < min)
		{
			x = pt[n].x;
			y = pt[n].y;
			min = pt[n].d;
		}
	}

	/*
cout << "sum = " << sum <<'\n';
		cout << "x = " << x << "y = " << y << '\n';
		cout << "tx = " << tx << "ty = " << ty << '\n';
*/

	if(tx != x  || ty != y)
	{
	
		slove(x, y);
	}

}


main()
{
	int x, y;
	int i, j;

	while(1)
	{
	for(i = 0;i < MAX;i++)
		for(j = 0;j < MAX;j++)
			map[i][j] = 0;


	while(1)
	{
		cin >> x >> y;

		if(x == -1 && y == -1)
			return 1;

		if(x == 0 && y == 0)
			break;
		map[x-1][y-1] = 1;
	}

	sum = 0;

	for(x = 0;x < MAX;x++)
		for(y = 0;y < MAX;y++)
		{
			if(map[x][y] == 1)
			{
			
				slove(x, y);
			}
		}

		cout << sum << '\n';
	}
}


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