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 |
Re:这个程序的测试数据是否有问题? 怎么我测了那么多都对,而且理论上我的程序也对,但总WA,高人看看(内附代码)In Reply To:Re:这个程序的测试数据是否有问题? 怎么我测了那么多都对,而且理论上我的程序也对,但总WA,高人看看(内附代码) Posted by:baseball at 2007-06-02 08:44:23 > Data里面的值都被你改写了,像else if(Data[x+1][y]<Data[x][y])这些类似的判断就无效了.不要用data存放结果.再开辟一个数组. #include <iostream.h> #include <stdlib.h> int Data[100][100]; int Da[100][100]={0}; int R,C; int Max_len=0; int Temp_len=0; int Go(int x,int y); int main(int argc, char *argv[]) { cin>>R>>C; int i,j; for(i=0;i<R;i++) { for(j=0;j<C;j++) cin>>Data[i][j]; } for(i=0;i<R;i++) { for(j=0;j<C;j++) { Temp_len=Go(i,j); if(Max_len<Temp_len) Max_len=Temp_len; } } cout<<Max_len; return EXIT_SUCCESS; } int Go(int x,int y) { if(Da[x][y]<0) return -Da[x][y]; int t=0; int len=0; int temp=0; while(t<4) { temp=0; switch(t) { case 0: if(x==0) break; else if(Data[x-1][y]<Data[x][y]) temp=Go(x-1,y); break; case 1: if(y==(C-1)) break; else if(Data[x][y+1]<Data[x][y]) temp=Go(x,y+1); break; case 2: if(x==(R-1)) break; else if(Data[x+1][y]<Data[x][y]) temp=Go(x+1,y); break; case 3: if(y==0) break; else if(Data[x][y-1]<Data[x][y]) temp=Go(x,y-1); break; } if(temp>len) len=temp; t++; } len+=1; Da[x][y]=-len; return len; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator