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

哪位大牛能帮我看一下啊,这道题都搞了整整一天了```wa得我都想哭了~~~郁闷ing``

Posted by cangratul at 2007-02-12 21:54:49 on Problem 1158
#include <stdio.h>
char min1(char x,char y)
{
	return x<y?x:y;
}
int main()
{
	unsigned short d[301]={0},min,t,D,T=0;
	struct junction
	{
		char c,r,t[2],c0,r0,c1,r1;
	}j[301];
	char map[301][301]={0},sc,de,mark[301]={0},c;
	short n,m,i,j1,j2,wait;
	scanf("%d %d %d %d",&sc,&de,&n,&m);
	for(i=1;i<=n;i++)
	{
		getchar();
		c=getchar();
		scanf("%d %d %d",&j[i].r,&j[i].t[0],&j[i].t[1]);
		if(c=='B') j[i].c0=0;
		else j[i].c0=1;
		j[i].r0=j[i].r;
	}
	j[sc].c=j[sc].c0;
	for(i=1;i<=m;i++)
	{
		scanf("%d %d %d",&j1,&j2,&c);
		map[j1][j2]=map[j2][j1]=c; 
	}
	j2=sc;
	while(1)
	{
		j1=j2;
		mark[j1]=1; min=60000;
		for(i=1;i<=n;i++)
		{
			if(mark[i]==0&&map[j1][i]!=0)
			{
				if(j[i].r0>T) {j[i].c1=j[i].c0; j[i].r1=j[i].r0-T;}
				else
				{
					t=(T-j[i].r0)%(j[i].t[0]+j[i].t[1]);
					if(t<j[i].t[!j[i].c0]) {j[i].c1=!j[i].c0; j[i].r1=j[i].t[!j[i].c0]-t;}
					else {j[i].c1=j[i].c0; j[i].r1=j[i].t[0]+j[i].t[1]-t;}
				}
				if(j[j1].c==j[i].c1) wait=0;
				else
				{
					if(j[j1].r!=j[i].r1) wait=min1(j[j1].r,j[i].r1);
					else
					{
						if(j[j1].t[j[i].c1]!=j[i].t[j[j1].c]) wait=j[i].r1+min1(j[j1].t[j[i].c1],j[i].t[j[j1].c]);
						else
						{
							if(j[j1].t[j[j1].c]!=j[i].t[j[i].c1]) wait=j[i].r1+j[j1].t[j[i].c1]+min1(j[j1].t[j[j1].c],j[i].t[j[i].c1]);
							else wait=-1;
						}
					}
				}
				if(wait!=-1)
				{
					D=wait+map[j1][i]+T;
					if(D<d[i]||d[i]==0)
					{
						d[i]=D;
						if(j[i].r0>D) {j[i].c=j[i].c0; j[i].r=j[i].r0-D;}
						else
						{
							t=(D-j[i].r0)%(j[i].t[0]+j[i].t[1]);
							if(t<j[i].t[!j[i].c0]) {j[i].c=!j[i].c0; j[i].r=j[i].t[!j[i].c0]-t;}
							else {j[i].c=j[i].c0; j[i].r=j[i].t[0]+j[i].t[1]-t;}
						}	
					}
				}
				if(d[i]!=0&&d[i]<min) {min=d[i]; j2=i;}
			}
		}
		if(min==60000) goto no;
		if(j2==de) goto yes;
		T=d[j2];
	}
yes:printf("%d\n",d[de]);return 0;
no: printf("0\n");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