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啊各位大虾们、、、(每次DFS时更新路径上的最大值最小值)#include <iostream> #include <cstring> #define SIZE 128 using namespace std; const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1}; int n,gmap[SIZE][SIZE]; bool vis[SIZE][SIZE]; bool legal(int x,int y) { return x >= 0 && x < n && y >= 0 && y < n && !vis[x][y]; } void DFS(int x,int y,int maxh,int minh,int dis) { vis[x][y] = true; for (int i = 0;i < 4;i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (!legal(nx,ny)) continue; int nmaxh = gmap[nx][ny] > maxh ? gmap[nx][ny] : maxh; int nminh = gmap[nx][ny] < minh ? gmap[nx][ny] : minh; if (nmaxh - nminh <= dis) DFS(nx,ny,nmaxh,nminh,dis); } } bool isok(int dis) { memset(vis,false,sizeof(vis)); DFS(0,0,gmap[0][0],gmap[0][0],dis); return vis[n-1][n-1]; } int work() { int high = 200,low = 0,mid,ans = 200; while (low < high) { mid = (high + low) / 2; if (isok(mid)) { ans = mid; high = mid - 1; } else low = mid + 1; } return ans; } int main() { int cas; scanf("%d",&cas); for (int c = 1;c <= cas;c++) { scanf("%d",&n); for (int i = 0;i < n;i++) for (int j = 0;j < n;j++) scanf("%d",&gmap[i][j]); printf("Scenario #%d:\n%d\n\n",c,work()); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator