BaoBao is taking a walk in the interval [0,n] on the number axis, but he is not free to move, as at every point (i−0.5) for all i∈[1,n], where i is an integer, stands a traffic light of type t
i
(t
i
∈{0,1}).
BaoBao decides to begin his walk from point p and end his walk at point q (both p and q are integers, and p
/*题目大意:Bao在数轴的间隔[0,n]上散步,但他不能自由移动,[1,n]处有n个路灯,
1代表绿灯可以行走,0代表红灯不能行走,红绿灯每过1秒都会改变(1变0,0变1),
求出走所有路径所用的时间(只能从前往后走,可以从0开始走,但路灯从1处才开始有)
解题思路:
例: 1 1 0 1 0
从0:1 3 4 5 6
从1: 1 2 3 4 除第一个数其他都为上一行数减二
从2: 2 3 4 除第一个数其他都和上一行数一样
从3: 1 2 所有数其他都为上一行数减二
从4: 2 除第一个数其他都都和上一行数一样
从中可以找出规律,若与前面的灯一样,则需要经过两秒,若不一样则只需一秒,
因为经过前面一定是绿灯,那此处本来是红灯,经过一秒刚好变成绿灯
*/
#include<iostream>
#include<cstdio>
#include<cstring>