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

Re:有谁帮我看一下?WA

Posted by BJ051155 at 2007-07-23 17:04:54 on Problem 2982
In Reply To:有谁帮我看一下?WA Posted by:BJ051155 at 2007-07-23 17:04:42
> #include <iostream>
> using namespace std;	
> int stackx[20000],stacky[20000];
> int cost[200][200];
> 
> int main(int argc, char* argv[])
> {
> 	short n,m,k;
> 	int a[105],b[105],c[105];
> 	while(scanf("%d%d%d",&n,&m,&k))
> 	{
> 		if(n==0&&m==0&&k==0)
> 			break;
> 		for(int i=0;i<k;i++)
> 			scanf("%d%d%d",&a[i],&b[i],&c[i]);
> 		for(i=0;i<200;i++)
> 			for(int j=0;j<200;j++)
> 				cost[i][j]=0;
> 		int qh=0,qe=1;
> 		stackx[qh]=0;
> 		stacky[qh]=0;
> 		while(qh<qe)
> 		{
> 			for(i=0;i<k;i++)
> 			{
> 				int x=stackx[qh]+a[i];
> 				int y=stacky[qh]+b[i];
> 				if(x>=0&&y>=0&&x<=n&&y<=m&&(cost[x][y]==0||cost[stackx[qh]][stacky[qh]]+c[i]<cost[x][y]))
> 				{
> 					stackx[qe]=x;
> 					stacky[qe]=y;
> 					qe++;
> 					cost[x][y]=cost[stackx[qh]][stacky[qh]]+c[i];
> 				}
> 			}
> 			qh++;
> 		}
> 		if(cost[n][m]==0)
> 			printf("-1\n");
> 		else
> 			printf("%d\n",cost[n][m]);
> 	}
> 	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