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 xiangchuwang at 2008-07-26 15:49:51 on Problem 1928
#include<stdio.h>
#include<math.h>
typedef struct node
{
	int x;
	int r;
	int c;
}jilu;

void sort(jilu a[],int n)
{
	int i,j,t;
	for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
		{
			if(a[i].x<a[j].x)
			{
				t=a[i].x;
				a[i].x=a[j].x;
				a[j].x=t;
				t=a[i].r;
				a[i].r=a[j].r;
				a[j].r=t;
				t=a[i].c;
				a[i].c=a[j].c;
				a[j].c=t;
			}
		}
		
		
}
int m(jilu a[],int n,int k)
{
	long sum2=0;
	int i=1,sum;
	
	if(k<2*(a[i].r+1)+1)
		return sum2;
	for(i=1;i<=n;i++)
		
	{ sum=0;
		if(i==1&&k>=2*a[i].r+1)
	{
	         sum+=a[i].r+1;sum2+=a[i].x;k=k-sum;
	}
	
	else{	
		
	 if(k>=(abs(a[i].r-a[i-1].r)+abs(a[i].c-a[i-1].c)+1+a[i].r))
	  {
	          	sum+=abs(a[i].r-a[i-1].r)+abs(a[i].c-a[i-1].c)+1;
	             sum2+=a[i].x;k=k-sum;
		}
		else break;
		
		
	}
	}
	return (sum2);
	
	
}
void main()
{
	int q,T,M,N,K,i,j,w,s=1;
	jilu record[102];
	scanf("%d",&T);
	for(q=1;q<=T;q++)
	{   s=1;
		scanf("%d %d %d",&M,&N,&K);
		for(i=1;i<=M;i++)
			for(j=1;j<=N;j++)
			{
				scanf("%d",&w);
				if(w!=0)
				{
					record[s].x=w;
					record[s].r=i;
                    record[s].c=j;
					s++;
				}
			}
			sort(record,s-1);
			
			printf("%d\n",m(record,s-1,K));
			
	}
}

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