Home > Back-end >  Train problem for help
Train problem for help

Time:04-22

, have N different length of the train tunnel of length L, grid, there are several specific car lamp is open, the rest are closed, when the train through the tunnel, for is in the midst of the tunnel in the car, should ensure that at least one car of the light is on, so be extra open some car lamp,
Write an algorithm that find train through the tunnel, the number of car (s) must be extra lights,
Enter the first line is N and L, the second line indicates car length, the third line said grid corresponding to the car lights on and off,
Input: the first line: 7 to 10
The second line: 5, 3, 4, 5 and 9 9 9
The third line: 1 0 0 0 1 0 0
Output: 2 (you can find a solution is a length of 4 and 9 respectively, the third and seventh car lamp)

My train of thought is a first began to turn on the light and the length is greater than or equal to L car the length of the corresponding to 0 (example: 0, 3, 4, 5 0 9 9), but the rest of the don't know what to do, between 0 hope bosses under the guidance ideas (python),

CodePudding user response:


  • Related