桌上纸杯有正放的,也有倒扣着的。现在要将纸杯按照正放、倒扣、正放的顺序进行排列。
杯子的顺序不能交换,但可以翻转。先给定一个初始状态数组(1 表示正放,0 表示倒扣),需要输出最少翻转操作的数目。
- 举例:[1,1,1,0,0,0,1,1,0,0,0,1,1],输出 2(需要翻转两次,中间的两个正放的杯子倒扣过来即可)。
- 输入范围:数组长度小于 2000 个,大于 3 个。以 2 作为输入的结尾。
- 注意:任何一组正放和倒扣的纸杯的数量都不能为 0
输入
10001010110101010010110110110011100101010110000111011000011100110011111111100011111100000010000100010010011011110101000001110000010110011110101110110001000110111100101000110010111110111100110111001011011011111100010010011100111010000001001011110010011011001101001110010010100100010111110100001111101110101110011101110010001001101010010010100000111001000000000000000111110010100011010010011111101100001001110101101101000010000101110100101111000010101001111010000110010110000001000001100110011001101100011000011000011100000110011100111001010000111000001010010111000110110100101101100110010110111101110100000101110111101111111001101101100000010100001111010011010101110010111010110001111111000000111100011101011100101111111000010010001010100110001110010000100000101011011000101100011101001111101001001001101010110111010000110000110100110111101010010000111110111000010011010111010100010000000000100100111100000101000100100001100110001101100010011000111101101101011011111101111100000000111101010011001010000111101101000001000001110110100010010000100111100101011110100001101000110011110001000000000101001011001000000001110111111111010011101111110010101000001110001001110111100110011011010000111111001110000001101101000110101001001010111100110001000111101101101111011010010110010111111100011000001101101011000101110111010000000100101000111110010100000110101001111011010110010101010001111001010011101110001101100000110001010000101010011111110111000010110010101110110101000110010100011011000001101011001111010110111000001111100101010001010011111000111110001101100100001010111001010001110000110110010000100001011001000111011001111100111110110011110110001000110000000110101011111011110111100111000011111101000011001111111011100001110100100000101110000000000011000101111110110001110011011011100011011101111010001011100101001101101111010111111101010100110000011111101001101010100110000001111010001110111000011101000000110000010010110111110010010110100011000111101100100100000011011111001110100111011101011001010011
输出
938
输入
01100011011101111001000011000110110001011100010101111001001000010001110010011010111001101011111010010101100001110001110101000000111011100011001001110011100110010111011111100101000111101011110010101111001010101101100101101011110000000011001000011000101110110001110101001010010111110010111111000000100000001101100000100001111000110101111101111011110000011110000111001111110100011000001001100000101101101011010111010111001011101000001110110111001110101100110010000110011110100000111010011001011111101011000101010100010111101010001010000010101100101101011011110110011010001110110110000001110011001001100000011011010001110111011101010000111101100001011110000000111101000001100111101011111000010100110000101010100000000111000011011100100111111000100011101101100011101010110000011101110111111000000010110001000011000001000111110110100010101110000110100101111011110001110111011110011011100010001010110001000001000010001111011110100100011001001110110101001100111011001001100011100100101011111110001111100001010100101101110000010100101110101000000111101110010010110110001011011001111011000001001101010000010011101011010000010100111010111101111001111001101110111001001100110101110100001001101011110100101001110101101101011001011111011001100010111001111011111100110110100101100011111100011110111010100100001000101111011100000110000010000001010011111111000101010101110111111111010011001110101000101011001000101011101100010110011110110011000001010000010100110010101011110100101100010000101011100001110011010100110101001000110011001011100110101100011000100110010100000010111101111101111101011010111100111010100010000001100001011011001000110010101101011110010111111101000111100000100011100000100011110100111011101110010110010000110000000001001110111010001100010101000110101010011010100001100101011010011000100000111000111000000001000100100111101111110010110010000101111000101101010111010101101001101101110010011000000111111100000000000010110111111101110100110011011110000010110100111011000010000000101101101100110101
输出
960