zoj 1622 Switch 开关灯 简单枚举
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
这道题很简单,我觉得之所以写是因为提供了自己的思路,在这里将奇数调为开,偶数调为关,
和为num1,这样可以得到另一面就是N-num1就是奇数调为关,偶数调为开,这样哪个结果小于N/2哪个就能成为最小的切换数
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
int a[10005];
int main()
{
int i,n,tempo,tempj,temp;
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
tempo=tempj=temp=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i%2==0)
{
if(a[i]==1)
tempj++;
else
tempo++;
}
else
{
if(a[i]==0)
tempj++;
else
tempo++;
}
}
if(tempj>tempo)
temp=tempo;
else
temp=tempj;
printf("%d\n",temp);
}
return 0;
}
zoj 1622 Switch 开关灯 简单枚举的更多相关文章
- UVA - 10167 - Birthday Cake (简单枚举)
思路:简单枚举 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include &l ...
- Java练习 SDUT-1959_简单枚举类型——植物与颜色
简单枚举类型--植物与颜色 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 请定义具有red, orange, yell ...
- hdu5073 简单枚举+精度处理
其实这题还是挺简单的,因为移动k个星球后,这k个星球的权值就可以变为0,所以只有剩下的本来就是连着的才是最优解,也就是说要动也是动两端的,那么就O(N)枚举一遍动哪些就好了. 我是在杭电oj题目重现的 ...
- UVa 725 简单枚举+整数转换为字符串
Division Write a program that finds and displays all pairs of 5-digit numbers that between them use ...
- ZOJ 3987 Numbers(Java枚举)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3987 题意:给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n ...
- zoj 3983 Crusaders Quest 思维+枚举
题目链接 这道题意思是: 给你一个长度为9的字符串,且只有3个a.3个g.3个o 问,你可以选择删除一段连续的串或者单个的字符也可以不删,最多会出现几个三子相连的子串 比如:agoagoago只有将两 ...
- ZOJ 3213 Beautiful Meadow 简单路径 插头DP
简单路径的题目,其实就是在状态后面多记了有多少个独立插头. 分类讨论独立插头: 1.只存在上插头或者左插头,可以选择作为独立插头. 2.都不存在上插头和左插头,选择作为独立插头的同时要标号为新的连通块 ...
- UVA 725 UVA 10976 简单枚举
UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...
- 使用if和switch制作简单的年龄生肖判断
-年 查询 --> var oDiv =document.getElementById("cont"); var oYear = document.getElementByI ...
随机推荐
- google maps v3 添加自定义图标(marker,overlay)
google搜了很久都没找到符合v3版本的google maps自定义图标,可以让图标使用自己的html,都是V2版本的,依靠重写google api属性来完成. 然后就找了个jquery下的goog ...
- Android:简单的开场界面
接通过ImageView创建一个全屏的图片: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...
- 同步or异步
一.什么是同步?什么是异步? 同步:如果有多个任务要执行,这些任务必须逐个执行,一个任务的执行会导致整个流程的暂时等待,这些任务没有办法并发地执行: 异步:如果有多个任务要执行,这些任务可以并发执行, ...
- Extension Method[上篇]
在C#3.0中,引入了一些列新的特性,比如: Implicitly typed local variable, Extension method,Lambda expression, Object i ...
- eclipse+pydev (python) 配置出错
错误: eclipse+pydev 配置出错,就是在选择python interpreter那一步: See error log for details.com.sun.org.apache.xerc ...
- poj 3267 The Cow Lexicon(dp)
题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...
- struts2关于package 的 namespace
namespace决定了action的访问路径,默认为"",可以接收所有路径的actionnamespace可以写为/ ,或者/xxx,或者/xxx/yyy,对应的action访问 ...
- 函数buf_LRU_free_block
/******************************************************************//** Try to free a block. If bpag ...
- 《深入Java虚拟机学习笔记》- 第17章 异常
<深入Java虚拟机学习笔记>- 第17章 异常
- AsyncEnumerableExtensions.cs z
public static class Extensions { public static async Task ForEachAsync<T, U>(this IEnumerable& ...