Tm I really can not think of what fun things ~ ~
This question is a pure simulation questions, just use a variable that represents the current cars with how many minutes
Not difficult to find this magical variable m can be expressed directly, but also can save a variable. . . (As if there is nothing with eggs)
See specifically explained codes :::
. 1 #include <the cmath> 2 #include <cstdio> . 3 #include <the iostream> . 4 #include <CString> . 5 #include <algorithm> . 6 the using namespace STD; . 7 const int N = 100005 ; // define a variable immutable . 8 int n-, m; . 9 int a [N], R & lt [N], G [N]; // distance between each intersection, red time (Red), green time (Green) 10 int main () { . 11 CIN >> >> n-m; // read 12 is for ( int I = . 1 ; I <n-; I ++) {// remember, there are n junction, the n-1 from only 13 is CIN >> A [I]; 14 } 15 for ( int I = . 1 ; I <= n; I ++) { // read red time 16 CIN >> R & lt [I]; . 17 } 18 is for ( int I = . 1 ; I <= n-; I ++) { // read green time . 19 CIN >> G [I]; 20 is } 21 is for ( int I = . 1 ; I <= n-; I ++) { // time to process 22 is IF(m% (R & lt [I] + G [I])> G [I]) m + = (R & lt [I] + G [I]) - m% (R & lt [I] + G [I]); // If the current time is not within the range of green light, will be added to the current time and the time m green intersection nearest to the difference between the current 23 is COUT m << << endl; // output time 24 + = a [I] m; // plus by the first time i to i + distance between an intersection 25 } 26 return 0 ; 27 } // perfect end Finally, i wish you all success program! ! !
La la la encourage new blogging about it ~ ~ ~