The main topic: there is a person, run a party, the first to have a gift. If more than one person arrives at the same time, go home farthest from the that, if still many people arrive at the same time, go to that number the biggest
Problem-solving ideas: The shortest water problem ...
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <cmath>using namespace STD;#define N 310#define INF 0x3f3f3f3fstructPeople {intLen, ID, start, speed;DoubleTime;} P[n];intDis[n][n], d[n];intN, M, K, ZZ;BOOLVis[n];intCMP (People A, people b) {if(fabs(A.time-b.time) <1e-7) {if(A.len = = B.len) {returna.ID > b.ID; }Else returnA.len > B.len; }Else returnA.time < B.time;}voidInit () {memset(Dis,0x3f,sizeof(dis)); for(inti =1; I <= N; i++) Dis[i][i] =0;intX, y, Z; for(inti =0; I < K; i++) {scanf("%d%d%d", &x, &y, &z); Dis[y][x] = min (dis[y][x], z); }scanf("%d", &zz); for(inti =1; I <= m; i++) {scanf("%d", &p[i].start); } for(inti =1; I <= m; i++) {scanf("%d", &p[i].speed); }}voidDijkstra () {memset(Vis,0,sizeof(VIS)); for(inti =1; I <= N; i++) D[i] = Dis[zz][i]; VIS[ZZ] =1; D[ZZ] =0; for(inti =2; I <= N; i++) {intX, t = INF; for(intj =1; J <= N; J + +)if(!vis[j] && d[j] < T) {t = d[j]; x = j; }if(t = = INF) Break; VIS[X] =1; for(intj =1; J <= N; J + +) {if(D[j] > D[x] + dis[x][j]) {D[j] = D[x] + dis[x][j]; } } }}voidSolve () {Dijkstra (); for(inti =1; I <= m; i++) {if(D[p[i].start] = = INF) {p[i].time = INF; P[i].len = INF; P[i].id = i; }Else{p[i].time = D[p[i].start] *1.0/p[i].speed; P[i].len = D[p[i].start]; P[i].id = i; }} sort (P +1, P + M +1, CMP);if(p[1].time = = INF)printf("No one\n");Else printf("%d\n", p[1].id);}intMain () { while(scanf("%d%d%d", &n, &m, &k)! = EOF) {init (); Solve (); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU-2145 ZZ ' s mysterious Present (shortest way)