1622_Switch
来源:互联网 发布:cnc编程用什么软件好 编辑:程序博客网 时间:2024/06/11 08:11
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
Author: SHI, Xiaohan
Source: Zhejiang University 2003 Summer Camp Qualification Contest
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
#include<iostream>
using namespace std;
#define max 10000
int main()
{
int num;
bool lig[max]={0};
int i;
int on_first,off_first;
while(cin>>num)//往简单的想,无非就是两种情况,首位为1或0;分别求出需要的次数比较
{
on_first=off_first=0;
for(i=0;i!=num;i++)
cin>>lig[i];
for(i=0;i!=num/2;i++)
{
if(lig[2*i]==1)//这两个判断得到010101需要换多少
++off_first;
if(lig[2*i+1]==0)
++off_first;
if(lig[2*i]==0)//这两个判断得到101010需要换多少
++on_first;
if(lig[2*i+1]==1)
++on_first;
}
if(num%2==1)
{
if(lig[num-1]==1)
++off_first;
if(lig[num-1]==0)
++on_first;
}
//cout<<off_first<<" "<<on_first<<endl;
cout<<(off_first<on_first?off_first:on_first)<<endl;
}
return 0;
}
- 1622_Switch
- 黑马程序员_switch理解
- 12_switch语句
- Java学习笔记_switch
- C++_Switch Statement
- Menu键_switch中设置
- javaSE学习07_switch语句
- asm source code note 1.7_switch case分支的实现
- c/c++_计算总运费_switch语句的使用
- 语句效率问题_switch和if-else相比
- 编程基础_switch case中多种case输出相同
- 黑马程序员__选择结构if语句_switch语句
- 笔试题_switch语句里default位置与执行问题
- 18_switch语句_基本用法_case穿透现象
- 【JavaSE学习笔记】选择结构语句_switch语句
- C语言32个关键字_switch,case break,default
- C编译器剖析_5.3.2 中间代码生成及优化_switch语句的翻译
- Java千百问_03基本语法(008)_switch如何使用
- 第 3次实验任务
- onCreateContextMenu 与 onCreateOptionsMenu比较与作用
- canvas学习网址归集
- 人的基本原则(看完终身受益) .
- JAVASE----08----String
- 1622_Switch
- 2:A-B Problem
- 百度me域名收录欠佳,站长如何应对?
- VC中Radio控件的用法(VC2008)
- 主流引擎网站提交地址
- Best Practices for Speeding Up Your Web Site
- ON_MESSAGE ,ON_COMMAND, , ON_NOTIFY
- 3520a新板做内存测试
- 第三次上机实验报告