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:又给大家拖后腿了。。。In Reply To:又给大家拖后腿了。。。 Posted by:earnAlive at 2014-04-17 18:38:20 > 花了两天,第一天撸了一下午,结果超时,想了一晚上没想出好方法。。。 > 第二天花了一早上,看各种大神的解题报告,最后撸了一下午,终于出来了,最郁闷的是,感觉没学到啥啊 > #include<stdio.h> > #include<stdlib.h> > #define SIZE 1000 > > int pair[SIZE][2]; > > typedef struct omg > { > int pos; > int pixel; > }omg; > > omg outpix[8*SIZE]; > int total,width,size1,size2; > > int get_value(int pos) > { > int i=0,p=0; > while(p<pos) > { > p+=pair[i++][1]; > } > return pair[i-1][0]; > } > > int get_code(int pos) > { > int max=0; > int row,col,t_pos; > int i,j; > int value=get_value(pos); > int t_value; > > row=(pos-1)/width; > col=(pos-1)%width; > for(i=row-1;i<=row+1;i++) > { > for(j=col-1;j<=col+1;j++) > { > t_pos=i*width+j+1; > if(i<0||j<0||j>=width||t_pos>total||t_pos==pos) > continue; > t_value=get_value(t_pos); > if(max<abs(t_value-value)) > max=abs(t_value-value); > } > } > return max; > } > > int cmp(const void* a,const void* b) > { > omg *x=(omg *)a; > omg *y=(omg *)b; > return x->pos-y->pos; > } > > int main() > { > int pixel,length; > int row,col; > int i,j,k; > int cur; > while(scanf("%d",&width)!=EOF) > { > if(width==0) > break; > size1=0; > total=0; > while(scanf("%d%d",&pixel,&length)!=EOF) > { > if(pixel==0&&length==0) > break; > pair[size1][0]=pixel; > pair[size1++][1]=length; > total+=length; > } > printf("%d\n",width); > cur=1; > size2=0; > for(k=0;k<=size1;k++) > { > row=(cur-1)/width; > col=(cur-1)%width; > for(i=row-1;i<=row+1;i++) > { > for(j=col-1;j<=col+1;j++) > { > int top=i*width+j+1; > if(i<0||j<0||j>=width||top>total) > continue; > outpix[size2].pos=top; > outpix[size2++].pixel=get_code(top); > } > } > cur+=pair[k][1]; > } > > qsort(outpix,size2,sizeof(omg),cmp); > omg temp=outpix[0]; > for(i=0;i<size2;i++) > { > if(outpix[i].pixel!=temp.pixel) > { > printf("%d %d\n",temp.pixel,outpix[i].pos-temp.pos); > temp=outpix[i]; > } > } > printf("%d %d\n",temp.pixel,total-temp.pos+1); > printf("0 0\n"); > } > printf("0\n"); > return 0; > } > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator