Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请问为什么此程序sample过了,但提交re?(内有代码)好心人帮忙看看..谢谢..希望frkstyc能来:)

Posted by wronger at 2006-09-24 20:32:51 on Problem 1009
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int width, leng, *pre, *now, *next;

int getvalue(int m){
	int max=0;
	if(m>0){
		if(abs(pre[m-1]-now[m])>max) max=abs(pre[m-1]-now[m]);
		if(abs(now[m-1]-now[m])>max) max=abs(now[m-1]-now[m]);
        if(abs(next[m-1]-now[m])>max) max=abs(next[m-1]-now[m]);
	}
	if(m<width-1){
        if(abs(pre[m+1]-now[m])>max) max=abs(pre[m+1]-now[m]);
		if(abs(now[m+1]-now[m])>max) max=abs(now[m+1]-now[m]);
        if(abs(next[m+1]-now[m])>max) max=abs(next[m+1]-now[m]);
	}
    if(abs(pre[m]-now[m])>max) max=abs(pre[m]-now[m]);
	if(abs(now[m]-now[m])>max) max=abs(now[m]-now[m]);
    if(abs(next[m]-now[m])>max) max=abs(next[m]-now[m]);
	return max;
}

typedef struct{
    int value, num;
} pair;

int main(){
    int i, j, v, x, y, an, *d, *b, *c, mid, k, zeron, flag, *tem;
	pair a[1000], r;
	while(scanf("%d", &width)){
		if(width==0){
			printf("0\n");
			break;
		}
		an=0; leng=0;
		while(scanf("%d%d", &x, &y)){
			if(x==0 && y==0) break;
			a[an].value=x; 
			a[an++].num=y;
			leng+=y;
		}
		leng=leng/width;
        d=(int*)malloc(width*sizeof(int));
		b=(int*)malloc(width*sizeof(int));
		c=(int*)malloc(width*sizeof(int));
        pre=d; now=b; next=c;
        mid=0;
        k=0;
		i=0;
		while(i<an){
            if(a[i].num>width-k){
				a[i].num-=width-k;
				while(k<width){
                    pre[k]=now[k]=a[i].value;
				    k++;
				}
				break;
			}
			else{
				while(a[i].num--){
					pre[k]=now[k]=a[i].value;
					k++;
				}
				i++;
			}
		}
		flag=0; r.value=-1;
		printf("%d\n", width);
		while(1){
			if(mid==leng-1){
				for(j=0; j<width; j++)
                    next[j]=now[j];
			}else{
				k=0;
                while(i<an){
                    if(a[i].num>width-k){
					    if(k==0 && a[i].num/width>2){
							flag=1; 
							zeron=(a[i].num/width-2)*width;
							a[i].num-=zeron;
							mid+=zeron/width;
						}
						a[i].num-=width-k;
						while(k<width){
							next[k]=a[i].value;
							k++;
						}
						break;
					}
					else{
						while(a[i].num--){
							next[k]=a[i].value;
							k++;
						}
						i++;
					}
				}
			}
			for(j=0; j<width; j++){
				v=getvalue(j);
                if(r.value==-1){
					r.num=1;
					r.value=v;
				}
				else if(v==r.value) r.num++;
				else{
					printf("%d %d\n", r.value, r.num);
					r.num=1;
					r.value=v;
				}
			}
			if(flag==1) flag++;
			else if(flag==2){
				if(r.value==0) r.num+=zeron;
				else{
					printf("%d %d\n", r.value, r.num);
					r.value=0;
					r.num=zeron;
				}
				flag=0;
			}
            mid++;
			if(mid==leng) break;
            tem=pre; pre=now; now=next; next=tem;
		}
		printf("%d %d\n", r.value, r.num);
		printf("0 0\n");
		free(d); free(b); free(c);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator