Switch
2015-12-05 23:36
295 查看
Switch
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
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.输入
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
输出
For each testcase output a line consists of only the least times of switches.示例输入
3 1 1 1 3 1 0 1
示例输出
1 0
提示
来源
示例程序
#include<iostream> using namespace std; int main() { int lights; while(cin>>lights) { bool *p0 = new bool[lights], *p1 = new bool[lights]; bool *L = new bool[lights]; int switch1 = 0, switch2 = 0; bool light; for(int i = 0; i < lights; i++) { cin>>light; if(i == 0) { *(p0 + i) = true; *(p1 + i) = false; } else { *(p0 + i) = !*(p0 + i - 1); *(p1 + i) = !*(p1 + i - 1); } if(light != *(p0 + i)) switch1++; if(light != *(p1 + i)) switch2++; } cout<<(switch1 > switch2 ? switch2 : switch1)<<endl; } return 0; }
相关文章推荐
- linux常用命令
- PHP
- codeforces 547B. Mike and Feet 单调栈
- 22
- 昂贵的珍珠垂饰
- 计算机网络_2_TCP/IP
- 去掉电脑快捷方式小箭头
- 第二百四十七天 how can I 坚持
- 查看Ubuntu/Redhat等Linux系统版本号等系统信息
- Number Steps
- 有趣的一天。。。。恰巧下雪
- CSS学习要点
- 106-背包问题
- 跨域解决方案总结
- 使用VMDepot镜像快速部署CKAN开放数据门户
- XDOC编辑器支持新版本Chrome浏览器
- 使用XDOC云服务做套打
- PDF生成进入基于Web服务的模板时代
- 基于Web服务的PDF 排版引擎 XDOC(mini)发布
- 用JS生成专业公文文档