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:哪位帮忙看一下,在我机器上好着,也做到了全是负数的情况,但是就是WA,不知为什么? Posted by:cfdream at 2007-04-18 00:32:23 > #include<iostream> > using namespace std; > int plus(int **arr,int lrud[4],int sum[4],int rectangle[4]) > { > int rows=rectangle[3]-rectangle[2]+1; > int cols=rectangle[1]-rectangle[0]+1; > for(int i=0;i<4;i++) > { > if(i==1||i==0) > { > int colth=lrud[i]; > for(int m=rectangle[2],j=0;j<rows;j++) > sum[i]+=arr[m+j][colth]; > }else{ > int rowth=lrud[i]; > for(int j=0,m=rectangle[0];j<cols;j++) > sum[i]+=arr[rowth][m+j]; > } > } > return 1; > } > void main() > { > int N; > cin>>N; > if(N<0||N>100) > exit(-1); > int sign=0,negative=-128; > int **arr=new int *[N]; > for(int i=0;i<N;i++) > { > arr[i]=new int[N]; > for(int j=0;j<N;j++){ > cin>>arr[i][j]; > int temp=arr[i][j]; > if(temp<-127||temp>127) > exit(-1); > if(temp>=0) > sign=1; > else if(temp>negative) > negative=temp; > } > } > if(sign==0) > cout<<negative; > else > { > int lrud[4]={0,N-1,0,N-1},sum[4]={0,0,0,0}; > int rectangle[4]={0,N-1,0,N-1}; > int layer=1; > while((lrud[0]!=lrud[1]&&lrud[1]>lrud[0])||(lrud[2]!=lrud[3]&&lrud[3]>lrud[2])) > { > plus(arr,lrud,sum,rectangle); > int temp=0,k=-1; > for(int i=0;i<4;i++) > if(sum[i]<temp) > { > temp=sum[i]; > k=i; > } > if(temp<0) > { > for(int j=0;j<4;j++) > sum[j]=0; > if(k==0||k==2) > lrud[k]++; > else lrud[k]--; > rectangle[k]=lrud[k]; > }else{ > for(int j=0;j<4;j++) > { > if(j==0||j==2) > lrud[j]++; > else lrud[j]--; > } > }//else > } > int all=0; > for(i=rectangle[2];i<=rectangle[3];i++) > for(int j=rectangle[0];j<=rectangle[1];j++) > all+=arr[i][j]; > cout<<all<<endl; > } > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator