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 heiye at 2008-11-11 13:22:34 on Problem 1928
没有算法的方法,由于数比较少,就直接写的.....

#include<stdio.h>
#include<math.h>
int main(void)
{
	int t,n,m,k,i,j,a[55][55],b[5],c[5],d[5];
	int tmp1,tmp2,sum;
	scanf("%d",&t);
	while(t--)
	{
		int h=0;
		sum=0;
		scanf("%d %d %d",&m,&n,&k);
		for(i=0;i<m;i++)
		{
			for(j=0;j<n;j++)
			{
				scanf("%d",&a[i][j]);
				if(a[i][j]!=0)
				{
					b[h]=i+1;
					c[h]=j+1;
					d[h]=a[i][j];
					h++;
				}
			}
		}
		for(j=1;j<4;j++)
		{
			for(i=0;i<4-j;i++)
			{
				if(d[i]<d[i+1])
				{
					tmp1=d[i];
					d[i]=d[i+1];
					d[i+1]=tmp1;
					tmp1=b[i];
					b[i]=b[i+1];
					b[i+1]=tmp1;
					tmp1=c[i];
					c[i]=c[i+1];
					c[i+1]=tmp1;
				}
			}
		}
		while(1)
		{
			tmp2=b[0]*2+1;
			if(tmp2>k) break;
			sum+=d[0];
			tmp2-=b[0];

			tmp2+=abs(c[0]-c[1])+abs(b[0]-b[1])+b[1]+1;
			if(tmp2>k) break;
			sum+=d[1];
			tmp2-=b[1];

			tmp2+=abs(c[1]-c[2])+abs(b[1]-b[2])+b[2]+1;
			if(tmp2>k) break;
			sum+=d[2];
			tmp2-=b[2];

			tmp2+=abs(c[2]-c[3])+abs(b[2]-b[3])+b[3]+1;
			if(tmp2>k) break;
			sum+=d[3];
			tmp2-=b[3];
			break;
		}
		printf("%d\n",sum);
	}
	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