ZZULI 1679 Switch

Switch

Time Limit:1000MS  Memory Limit:65536K
Total Submit:43 Accepted:23

Description

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
思路:其实很简单,但是还是想了很长时间才想明白!题意就是给你一组数只有0和1,欲使相邻两个数不相同需要改变多少次求的是次数最少的;比如1 1 1 有两种结果 1 0 1 和0 1 0;所以最少的次数是1;
#include
int a[10001],b[10001],c[10001];
int main()
{
	int i,x,an1,an2,n;//an1和an2用来记录次数
    while(scanf("%d",&n)!=EOF)
	{
		for(i=0;ian2?an2:an1;
		printf("%d\n",an1);
	}
	return 0;
}


你可能感兴趣的:(数学)