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

好像写复杂了,注意对impossible的判断,而且我觉得起点和终点可能有加油站,这个要考虑一下,当初我就是跌在impossible的判断上了

Posted by sunmoonstar_love at 2005-09-06 20:49:23 on Problem 2465
In Reply To:无语了,,不过好像我的错不是那个,,那位大侠救救我吧, Posted by:Essence_me at 2005-09-06 20:44:34
> #include <stdio.h>
> #define min(x,y) ((x<y)?(x):(y))
> long station[101][201];
> void main()
> {
> 	long i,j,n,p,last,dis,price,min;
> 	scanf("%ld",&n);
> 	for(i=0;i<=100;i++)
> 		for(j=0;j<=200;j++)
> 		{
> 			station[i][j]=-1;
> 		}
> 	p=1;
> 	station[0][100]=0;
> 	last=0;
> 	while(scanf("%ld %ld",&dis,&price)!=EOF)
> 	{
> 		for(i=0;i<=200;i++)
> 		{
> 			if(i+dis-last<=200&&station[p-1][i+dis-last]!=-1&&i!=0)
> 			{
> 				station[p][i]=min(station[p-1][i+dis-last],station[p][i-1]+price);
> 			}
> 			else if(i+dis-last<=200&&station[p-1][i+dis-last]!=-1&&i==0)
> 			{
> 				station[p][i]=station[p-1][i+dis-last];
> 			}
> 			else
> 			if(station[p][i-1]!=-1)
> 				station[p][i]=station[p][i-1]+price;
> 		}
> 		last=dis;
> 		p++;
> 	}
> 	if(last!=n)
> 	{
> 		min=-1;
> 		for(i=100+n-last;i<=200;i++)
> 		{
> 			if(station[p-1][i]!=-1)
> 			{
> 				if(min==-1)min=station[p-1][i];
> 				else if(min>station[p-1][i])min=station[p-1][i];
> 			}
> 		}
> 		if(min==-1)printf("Impossible\n");
> 		else printf("%ld\n",min);
> 	}
> 	else
> 	{	
> 		min=-1;
> 		for(i=100;i<=200;i++)
> 		{
> 			if(station[p-1][i]!=-1)
> 			{
> 				if(min==-1)min=station[p-1][i];
> 				else if(min>station[p-1][i])min=station[p-1][i];
> 			}
> 		}
> 		if(min==-1)printf("Impossible\n");
> 		else printf("%ld\n",min);
> 	}
> }
> 

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