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 |
想不出我的代码为什么会超时...希望大家多多指教#include <stdio.h> #include <memory.h> #include <stdlib.h> #include <malloc.h> #define map(x,y) *(map+(x)*n+(y)); int *map; int n,m; int main() { int *value,*map,real; int i,j,x,y,ii,jj,b=0,k; scanf("%d%d",&n,&m); map=(int *)malloc(n*m*sizeof(int)); value=(int *)malloc(n*m*sizeof(int)); memset(value,0,n*m*sizeof(int)); for(i=0;i<n*m;i++) scanf("%d",map+i); b=1; while(b) { b=0;ii=0; for(i=0;i<m;i++) { for(j=0;j<n;j++,ii++) for(k=0;k<4;k++) { x=j;y=i; switch(k) { case 0:y++;jj=ii+n;break; case 1:x++;jj=ii+1;break; case 2:y--;jj=ii-n;break; case 3:x--;jj=ii-1;break; default: return 1; } if((x<0)||(y<0)||(x>=n)||(y>=m))continue; if(*(map+ii)<*(map+jj)&&(*(value+jj)+1>*(value+ii))) { value[ii]=value[jj]+1; b=1; } } } } for(i=0;i<n*m;i++) { if(*(value+i)>b)b=*(value+i); } printf("%d",b+1); free(map); free(value); return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator