| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
老是WA。麻烦大家帮忙看看。我的思路是机器人总是选择距离它最近的G。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator