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 201321010312 at 2014-06-18 21:29:38 on Problem 1062
#include <iostream>
#include <queue>
#include <list>
#include<cstring>
using namespace std;
int n,m;
int vis[102];
int dist[102];
int const inf= 0xffffff; 
typedef pair<int,int>pii;
priority_queue<pii,vector<pii>,greater<pii> >q;
typedef struct 
{
	int t,vi,s;
}edge;
edge e;
list<edge> l[102];
struct object
{
	int p,l;
}object[102];
int dijstra(int a)
{
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
		dist[i]=inf;
	}
	dist[0]=0;
	q.push(make_pair(dist[0],0));
	while(!q.empty())
	{
		pii u=q.top();
		q.pop();
		int x=u.second;
		if(vis[x])continue;
		vis[x]=true;
		if(object[x].l<=a&&object[x].l>=a-m)
		{
			for(list<edge>::iterator iter=l[x].begin();iter!=l[x].end();iter++)
			{
				if(dist[(*iter).t]>dist[x]+(*iter).vi)
				{
					dist[(*iter).t]=dist[x]+(*iter).vi;
					q.push(make_pair(dist[(*iter).t],(*iter).t));
				}
			}
		}
	
	}
	return dist[1];
}
	
int main()
{
	int x,k;
  while(cin>>m>>n)
  {
	  for(int i=1;i<=n;i++)
	  {
		  cin>>object[i].p>>object[i].l>>x;
		  e.s=0;e.t=i;e.vi=object[i].p;
		  l[0].push_back(e);
		  for(int j=1;j<=x;j++)
		  {
			  cin>>e.s>>e.vi;
			  e.t=i;
			  l[e.s].push_back(e);
		  }
	  }
	  int min=100000;
	  for(int i=object[1].l+m;i>0&&i>object[1].l-m;--i)
	  {
		  object[0].l=object[1].l;
		  k=dijstra(i);
		  if(min>k)
		  {
			  min=k;
		  }
	  }
	  cout<<min<<endl;
  }
	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