| ||||||||||
| 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 了无数次了,那位帮忙看一下#include <iostream>
using namespace std;
const int N = 100;
const int d[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int a[N][N];
int n;
bool flag[N][N];
int list[N * N];
inline int abs(int x)
{
return x > 0 ? x : -x;
}
inline bool Valid(int x, int y)
{
return x >= 0 && x < n && y >= 0 && y < n;
}
bool Check(int lim)
{
int s, t, i, j, x, y;
list[0] = 0;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
flag[i][j] = false;
flag[0][0] = true;
for (s = 0, t = 1; s < t; s++)
{
for (i = 0; i < 4; i++)
{
x = list[s] / n + d[i][0];
y = list[s] % n + d[i][1];
if (Valid(x, y) && !flag[x][y] && abs(a[x][y] - a[list[s] / n][list[s] % n]) <= lim)
{
if (x == n - 1 && y == n - 1)
return true;
flag[x][y] = true;
list[t++] = x * n + y;
}
}
}
return false;
}
int main()
{
int i, j, up, low, mid;
scanf("%d", &n);
for (i = 0; i < n; i++)
for (j = 0;j < n; j++)
scanf("%d", &a[i][j]);
low = 0;
up = 110;
while (up > low)
{
mid = (up + low) / 2;
if (Check(mid))
up = mid;
else low = mid + 1;
}
printf("%d\n", up);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator