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<algorithm> using namespace std; #include<stdio.h> int **N,R,C,num[105][105],T[105][105]; void getxy(int &x, int &y,int n) { x=n/C; y=n-n/C*C; } bool cmp(int *a,int *b) { return a[0]<b[0]; } int main() { int i,j; N=new int*[10005]; for(i=0;i<10005;i++) { N[i]=new int[2]; } scanf("%d %d",&R,&C); for(i=0;i<R;i++) for(j=0;j<C;j++) { scanf("%d",&N[i*C+j][0]); N[i*C+j][1]=i*C+j; T[i][j]=N[i*C+j][0]; } sort(N,N+R*C,cmp); int max=0; for(i=0;i<R*C;i++) { int x,y; getxy(x,y,N[i][1]); if(x>0) { if(T[x-1][y]>T[x][y]&&num[x-1][y]<=num[x][y]) { num[x-1][y]=num[x][y]+1; if(max<num[x-1][y]) max=num[x-1][y]; } } if(x<R-1) { if(T[x+1][y]>T[x][y]&&num[x+1][y]<=num[x][y]) { num[x+1][y]=num[x][y]+1; if(max<num[x+1][y]) max=num[x+1][y]; } } if(y>0) { if(T[x][y-1]>T[x][y]&&num[x][y-1]<=num[x][y]) { num[x][y-1]=num[x][y]+1; if(max<num[x][y-1]) max=num[x][y-1]; } } if(y<C-1) { if(T[x][y+1]>T[x][y]&&num[x][y+1]<=num[x][y]) { num[x][y+1]=num[x][y]+1; if(max<num[x][y+1]) max=num[x][y+1]; } } } printf("%d\n",max+1); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator