Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
【求助】实在不知道错哪,所有discuss的数据都过了。。。#include<stdio.h> #include<string.h> #define MAXNUM 5000 #define inf 100000000 int dist[MAXNUM]; int numOfPoint; int numOfEdge; struct _edge { int s,e; int v; }edge[99999]; struct _point { int level; int price; }point[MAXNUM]; void dijkstra(int dS,int dE) { int d[MAXNUM]; int i,j; for(i=1;i<=numOfPoint;i++) d[i] = inf; d[1] = 0; bool chosen[MAXNUM]={false}; chosen[1] = true; int curPoint=1,minD; for(i=0;i<numOfPoint;i++) { for(j=0;j<numOfEdge;j++) { if(edge[j].s == curPoint && point[ edge[j].e ].level <= dE && point[ edge[j].e ].level >= dS) { if(d[ edge[j].e ] >= d[ curPoint ] + edge[j].v) d[ edge[j].e ] = d[ curPoint ] + edge[j].v; } } minD = inf; for(j=1;j<=numOfPoint;j++) { if(minD > d[j] && !chosen[j]) { minD = d[j]; curPoint = j; } } chosen[curPoint] = true; } for(i=1;i<=numOfPoint;i++) { if(d[i] + point[i].price < dist[i]) dist[i] = d[i] + point[i].price; } } int main() { int m,n,numOfR,countE=0,minlevel = 10000000; int value[MAXNUM];//The value of each item. scanf("%d%d",&m,&n); numOfPoint = n; int i,j; for(i=1;i<=n;i++) { dist[i] = inf; scanf("%d%d%d",&point[i].price,&point[i].level,&numOfR); if(minlevel > point[i].level) minlevel = point[i].level; for(j=0;j<numOfR;j++) { edge[countE].s = i; scanf("%d%d",&edge[countE].e,&edge[countE].v); countE++; } } numOfEdge = countE; if(minlevel < point[1].level - m) minlevel = point[i].level - m ; for(i = minlevel;i<=point[1].level;i++) { dijkstra(i,i+m); } int minMoney=100000000; for(i=1;i<=numOfPoint;i++) { if(minMoney > dist[i]) minMoney = dist[i]; } printf("%d\n",minMoney); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator