Uvalive 6485 Electric Car Rally (BFS,PQ)

Source: Internet
Author: User

Https://icpcarchive.ecs.baylor.edu/index.php?

option=com_onlinejudge&itemid=8&page=show_problem&problem=4496

In an attempt to demonstrate the practicality of electric cars, Eleccarco is sponsoring a cross-country
Road rally. There is n charging stations for the rally where cars is check in and charge their batteries.
The rally may require multiple days ' travel. Each car can travel four hours (minutes) between
Charges. A car must be plugged to a charger for both minutes for each minute of travel time. Cars
Start the rally at noon in the first day, fully charged. Cars is permitted remain at a station even after
They is fully charged.
It is a possible to drive directly between select pairs of stations. Variations in TRAFC conditions,
Road conditions, availability of HOV lanes, etc., result in different travel times along each route de-
Pending upon the time in which travel along, that route begins. All roads is two-way, and the
Prevailing conditions affect travel in both directions.
The winner is the first car to reach checkpoint n? 1, starting form checkpoint 0. Other than the
Starting and ending conditions, cars may pass through the stations on any order, and need not visit all
Stations to complete the course.
Write a program to determine the earliest time, expressed as the total number of minutes elapsed
Since the start of the rally, at which a car could reach the final checkpoint.
Input
There'll is several test cases in the input. Each test case is starts with a line containing n (1≤n≤500),
The number of stations, and M (1≤m≤1), the number of connecting road segments.
This was followed by M blocks and each block describing one road segment. A Road Segment Block has
The following structure:
Each of the block begins with a single line containing the integers, A and B (0≤a, b≤n? 1, a? = b).
These numbers is the checkpoints connected by that segment. The Connections is undirected:a
Segment permitting-Station A-station B would also allow travel from station B to station A.
This was followed by from one to twenty ' travel lines ' describing travel times. Each of the travel lines
Contains 3 Numbers:start, Stop, (0≤start < stop≤1, 439), and T ime (0 < T IME < 1, 000). Start
And Stop is the time of day (expressed in minutes since midnight) described by this line, and T IME
Is the travel time, in minutes, required to traverse this road segment if travel begins at any time
range [Start.. Stop], inclusive. The first travel line in a block would have a start time of 0 (midnight, or
00:00). The final travel line in a block would have a stop time of 1439 (i.e, 23:59, or 1 less than hours
Times minutes). Adjacent travel lines in the input would be arranged in order, and the start time of
The higher than the stop time of the preceding line. The travel lines would cover
All times from 00:00 to 23:59.
Input would end with a line with the 0s. All test cases would describe a course that can be completed
By the cars.
Output
For each test case, output a single integer representing the smallest number of minutes needed to
Complete the rally. Output no spaces, and do not separate answers with blank lines.
Sample Input
4 4
0 1
0 1439 100
0 2
0 1439 75
1 3
0 720 150
721 824 100
825 1000 75
1001 1439 150
2 3
0 1439 150
3 2
0 1
0 10 200
11 1439 300
1 2
0 10 200
11 1439 300
4 3
0 1
0 719 500
720 1439 240
1 2
0 964 500
965 1439 2
2 3
0 971 500
972 1439 3
0 0
Sample Output
180
2360
255


Test instructions

Give an out-of-direction picture, starting at 0 o ' 12:00 noon (fully charged. Support 240 minutes away), at every point can be charged, charge 2 minutes of energy run 1 minutes, each road by minutes divided into a number of time periods. Each time period passes this road time is ti. Ask at least how long it will take to reach N-1 point.

Analysis:

Bfs+ priority queue. Prioritize the team by time. Pay attention to the storage of the charge (of course there are other methods). Because the charge time is assumed to be odd. Save with int will lose 0.5. The second is to run two cycles (two days).

There are many methods of weighing, the more common is to open two-dimensional, position and remaining power, my method is to open one-dimensional relaxation, will be charged to 0 (x.time-x.power). Be careful that the time period is not divided into 1-20 items as described in the description of the topic (this was followed by the twenty ' travel lines ' describing travel times.), but there are 24 of them, damn it. Illegal data, WA took me two days. have become WA digging machine. Handed over more than 70 A,total submissions only 210. The whole OJ's IQ was pulled down by me.


/* * * author:fcbruce * * Time:sun 06:44:35 PM CST * */#include <cstdio> #include <iostream> #in Clude <sstream> #include <cstdlib> #include <algorithm> #include <ctime> #include <cctype > #include <cmath> #include <string> #include <cstring> #include <stack> #include <queue > #include <list> #include <vector> #include <map> #include <set> #define SQR (x) ((x) * (x)) #  Define LL long long#define ITN int#define INF 0x3f3f3f3f#define PI 3.1415926535897932384626#define eps 1e-10#ifdef _WIN32 #define LLD "%i64d" #else #define LLD "%lld" #endif # define MAXM 2333#define maxn 507using namespace Std;struct _record{I  NT START[24],STOP[24],TIME[24]; int cnt;} W[maxm];int fir[maxn];int u[maxm],v[maxm],nex[maxm];int e_max=0;int vis[maxn];bool go[24];inline int ReadInt () {int  flag=0;  int data=0;  Char Ch=getchar ();    while (ch< ' 0 ' | | ch> ' 9 ') {if (ch== '-') flag=1;  Ch=getchar (); } do {Data=data*10+ch-' 0 ';  Ch=getchar ();  }while (ch>= ' 0 ' && ch<= ' 9 ');  if (flag) Data=-data; return data;}  inline void Add_edge (int _u,int _v) {int &e=e_max;  e++;  U[e]=_u;v[e]=_v;  Nex[e]=fir[u[e]];fir[u[e]]=e;    for (int i=0,start,stop=0,time,j=0;stop!=1439;i++) {start=readint ();    Stop=readint ();    Time=readint ();    W[e].start[j]=w[e+1].start[j]=start;    W[e].stop[j]=w[e+1].stop[j]=stop;    w[e].time[j]=w[e+1].time[j]=time*2;  W[e].cnt=w[e+1].cnt=++j;  } e++;  U[e]=_v;v[e]=_u; Nex[e]=fir[u[e]];fir[u[e]]=e;}  struct heap_node{int pos,time,power;  BOOL operator < (const heap_node &_) Const {return time>_.time;  }};p riority_queue

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Uvalive 6485 Electric Car Rally (BFS,PQ)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.