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 |
Run time error 一般是有哪些原因啊?我程序写的应该没有问题的,先找最低点,然后DFS。 但老是Run time error #include <iostream.h> #include <stdlib.h> int i,j; int R,C; int *h, *l; int findmin(int i, int j) { if(i-1 >= 0) if(h[i*R+j]>h[(i-1)*R+j]) return 0; if(i+1 < R) if(h[i*R+j]>h[(i+1)*R+j]) return 0; if(j-1 >= 0) if(h[i*R+j]>h[i*R+j-1]) return 0; if(j+1 < C) if(h[i*R+j]>h[i*R+j+1]) return 0; return 1; } inline int max(int i,int j) { return (i>j)?i:j; } int findmax(void) { int f=0; for(i=0;i<R;i++) for(j=0;j<C;j++) f=max(f,l[i*R+j]); return f; } void Adjust(int i,int j) { if(i-1 >= 0) if(h[i*R+j] < h[(i-1)*R+j]) if(l[(i-1)*R+j] < l[i*R+j]+1) { l[(i-1)*R+j] = l[i*R+j]+1; Adjust(i-1,j); } if(i+1 < R) if(h[i*R+j] < h[(i+1)*R+j]) if(l[(i+1)*R+j] < l[i*R+j]+1) { l[(i+1)*R+j] = l[i*R+j]+1; Adjust(i+1,j); } if(j-1 >= 0) if(h[i*R+j] < h[i*R+j-1]) if(l[i*R+j-1] < l[i*R+j]+1) { l[i*R+j-1] = l[i*R+j]+1; Adjust(i,j-1); } if(j+1 < C) if(h[i*R+j] < h[i*R+j+1]) if(l[i*R+j+1] < l[i*R+j]+1) { l[i*R+j+1] = l[i*R+j]+1; Adjust(i,j+1); } } int main() { cin>>R>>C; h = (int *)malloc(R * C * 4); l = (int *)malloc(R * C * 4); for(i=0;i<R;i++) for(j=0;j<C;j++) { cin>>h[i*R+j]; l[i*R+j]=0; } /* find the local minimums*/ for(i=0;i<R;i++) for(j=0;j<C;j++) l[i*R+j]=findmin(i,j); for(i=0;i<R;i++) for(j=0;j<C;j++) { if(l[i*R+j]==1) Adjust(i,j); } cout<<findmax(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator