原题链接: https://codeforces.com/contest/1077/problem/B


样例:

Examples
Input
10
1 1 0 1 1 0 1 0 1 0
Output
2
Input
5
1 1 0 0 1
Output
0
Input
4
1 1 1 1
Output
0

题意: 对于along,他认为只要一个寝室关了灯,而与该寝室相邻的灯都亮着的话,那么他就会改变这种状态,即断掉其中一个寝室的闸门。问给定一系列寝室的状态。问along不想看到别人孤独需要断掉的寝室闸门最小数。

解题思路: 对于该题,我们直接模拟即可,找到关灯的寝室然后判断相邻寝室是否都亮着,若亮着把右边的关掉(为了使断闸数最小,关右边可以使解最优),并统计断闸次数。则此题易解。

AC代码:

/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h> //POJ不支持#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pairusing namespace std;const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e2+2;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//int n,a[maxn];
int main(){//freopen("in.txt", "r", stdin);//提交的时候要注释掉IOS;while(cin>>n){rep(i,0,n-1)cin>>a[i];int sum=0;rep(i,1,n-2){if(a[i]==0&&a[i-1]==1&&a[i+1]==1){sum++;a[i+1]=0;i++;}}cout<<sum<<endl;}return 0;
}

B. Disturbed People(模拟) Codeforces Round #521 (Div. 3)相关推荐

  1. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C 1 /* 2 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 3 模拟题:蛮恶心的 ...

  2. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <al ...

  3. CodeForces Round #521 (Div.3) B. Disturbed People

    http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...

  4. Codeforces Round #521 (Div. 3) B. Disturbed People

    There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house ...

  5. Codeforces Round #521 (Div. 3) B - Disturbed People (贪心)

    题目链接:http://codeforces.com/contest/1077/problem/B 题意:给你一长度为n的01序列.0表示当前位置的房子灯是灭的,1表示当前房子的位置灯是亮的.判断某个 ...

  6. Codeforces Round #521 (Div. 3) B. Disturbed People 思维

    题解 题目大意 n个灯0关灯1开灯 101则中间的睡不着 问最少关掉多少个灯可以全都能睡着 遇见101则将后面的1的灯泡关掉 这样解决10101的问题 计数输出即可 AC代码 #include < ...

  7. Codeforces Round #521 (Div. 3)

    题目链接:http://codeforces.com/contest/1077 A.Frog Jumping 解题思路:作差再判断最后是否还要向右跳一次即可. AC代码: 1 #include< ...

  8. Codeforces Round #521 (Div.3)题解

    A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...

  9. 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels

    题目传送门 1 /* 2 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 3 很挫的判断四个方向是否OK 4 */ 5 #incl ...

最新文章

  1. 一句话搞定deepin中安装cuda的问题
  2. dsp处理浮点数_关于IQMATH和浮点数在DSP的深入理解
  3. android 8 esp8266,ESP8266 WIFI模块学习之路(8)——自写Android手机APP控制直流电机正反转...
  4. 【网络安全】身份验证凭证为何如此重要?
  5. Java的finally理解
  6. 转载:iOS 8 自适应 Cell
  7. SCVMM 2012 R2---添加Hyper-V虚拟机
  8. Houdini 官方HDA SideFX Labs 安装
  9. 异常来自HRESULT.0x80029C4A(TYPE_E_CANTLOADLIBRARY)的解决方法
  10. Appium+python(1):python运行真机App程序示例
  11. 几款非常优秀且常用的代码编辑器
  12. 产品分析报告-思维导图
  13. Java—ISBN号码问题
  14. 窗口透明化 AlphaBlend
  15. 电路模型和电路定律(Ⅰ)
  16. 想学机器学习吗?带坑的那种
  17. pandas 如何创建空的DataFrame
  18. 基于web的HMI / SCADA软件
  19. pc端微信分享(不是直接分享)
  20. 《经典算法案例》:听英文神曲不误算法

热门文章

  1. Android UI 测试框架Espresso详解
  2. 微信小程序开发之组件official-account(配置公众号关注组件)
  3. DAZ STUDIO 快速渲染技巧
  4. Gauss数据库初识
  5. Excel技巧—两招轻松搞定汉字转拼音
  6. MySQL轻快入门2021.3.19(常用函数)
  7. 均值归一化_深度神经网络中的归一化技术
  8. 【codevs 4246】奶牛的身高 差分约束
  9. linux崩溃mysql导出_Linux 文件系统引起的云盘文件系统异常导致 MySQL 数据页损坏事故恢复复盘...
  10. python走迷宫_Python使用Tkinter实现机器人走迷宫