zoukankan      html  css  js  c++  java
  • ZOJ Problem Set–1622 Switch

    Time Limit: 2 Seconds      Memory Limit: 65536 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


    Author: SHI, Xiaohan
    Source: Zhejiang University 2003 Summer Camp Qualification Contest

    #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;
    
    }
  • 相关阅读:
    控件显示和隐藏
    删除标题和边框
    界面图片
    VC界面最前端显示
    在VC++6.0开发中实现全屏显示
    VC比例放大缩小
    plsql dev
    通过OCCI连接oracle(C++)
    VC++使用Pro*CC++
    文件对话框
  • 原文地址:https://www.cnblogs.com/malloc/p/2429135.html
Copyright © 2011-2022 走看看