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

怎么错了,大牛帮个忙看看!!

Posted by hdjtdxacm at 2008-12-11 19:23:56 on Problem 2751
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct endea
{
	char a,b;
}a[10001];
int fun1(const void *x,const void *y)
{
	endea *c,*d;
	c=(endea *)x;
	d=(endea *)y;
	return c->a-d->a;
}
int fun2(const void *x,const void *y)
{
	endea *c,*d;
	c=(endea *)x;
	d=(endea *)y;
	return d->b-c->b;
}
int main()
{
	int a1,b1,i,j,k,s,n,m,T;
	while(1)
	{
        scanf("%d",&n);
        if(n==0)
        break;
		j=0;
		k=10001;
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&a1,&b1);
			if(a1==0&&b1==0)
			    continue;
			if(a1<b1)
			{
       			j++; 
				a[j].a=a1;
				a[j].b=b1;
			}
			else
			{
   				k--;
				a[k].a=a1;
				a[k].b=b1;
			}
		}
		s=10000-k+1;
		qsort(a+1,j,sizeof(a[0]),fun1);
		qsort(a+k,s,sizeof(a[0]),fun2);
		for(i=j+1,m=k;m<=10000;i++,m++)
		{
			a[i].a=a[m].a;
			a[i].b=a[m].b;
		}
		j+=s;
		m=j;
		T=0;
		i=1;
		j=1;
		while(1)
		{
			while(a[i].a==0)
				i++;
			if(i>m||j>m)
				break;		
			while(a[j].b==0)
				j++;
			if(i<=j)
			{
				T+=a[i].a;
				a[i].a=0;
				continue;
			}
			else
			{
				if(a[i].a==a[i].b)
				{
					T+=a[i].a;
					a[i].a=a[j].b=0;
					continue;
				}
				else if(a[i].a>a[j].b)
				{
					T+=a[j].b;
					a[i].a-=a[j].b;
					a[j].b=0;
					continue;
				}
				else
				{
					T+=a[i].a;
					a[j].b-=a[i].a;
					a[i].a=0;
					continue;
				}
			}
		}
	for(;j<=m;j++)
		T+=a[j].b;
     printf("%d\n",T);
	}
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