Diwali Connection

0

0 votes
Easy, greedy, binaryconversion
Problem

In Diwali lighting,n light bulbs are connected by a wire. Each bulb has a switch associated with it, however, due to faulty wiring, a switch also changes the state of all the bulbs to the right of the current bulb. Given an initial state of all bulbs, find the minimum number of switches you have to press to turn on all the bulbs. You can press the same switch multiple times.

INPUT:

Initial state of any bulb can be represented as 1->ON 0->OFF.

The initial state of bulbs would be given by  n bit Integer where ith bit represent the state of the ith bulb.

T be the number of test cases. Following T lines contains n bit Integer representing the state of n bulbs.

1<=T<=106

1<=X<=109

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
Explanation : 
5->101 so 2 bits are set
Editor Image

?