ZOJ1622(Switch)

Switch

Time Limit: 1 Second      Memory Limit: 32768 KB

There are N lights in a line. Given the states (on/off) of the lights, your task is to determine at least how many lights should be switched (from on to off, or from off to on), in order to make the lights on and off alternatively.


Input

One line for each testcase.

The integer N (1 <= N <= 10000) comes first and is followed by N integers representing the states of the lights ("1" for on and "0" for off).

Process to the end-of-file.


Output

For each testcase output a line consists of only the least times of switches.


Sample Input

3 1 1 1
3 1 0 1


Sample Output

1
0

 

 

//1824108 2009-04-08 16:04:53 Judge Internal Error  1622 C++ 0 0 Xredman 
//1824113 2009-04-08 16:07:08 Accepted  1622 C++ 0 184 Xredman 
#include <iostream>
using namespace std;

int convert(int cc)
{
    
if(cc == 1)
        
return 0;
    
else
        
return 1;
}


int main()
{
    
int n, s1, s2;
    
int st1;
    
int tt;
    
while(cin>>n)
    
{
        st1 
= 1;
        s1 
= s2 = 0;
        
while(n--)
        
{
            cin
>>tt;
            
if(tt != st1)
                s1
++;
            
else
                s2
++;
            st1 
= convert(st1);
        }

        
if(s1 < s2)
            cout
<<s1<<endl;
        
else
            cout
<<s2<<endl;
    }

    
return 0;
}

 

你可能感兴趣的:(switch)