Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest
链接:https://codeforces.com/contest/1141/problem/B
题意:
给n个数,0代表工作,1代表休息,求能连续最大的休息长度。
可以连接首尾。
思路:
求普通连续,当第一个时间和最后一个时间都休息的时候加上去判断一下。
代码:
#include <bits/stdc++.h>
using namespace std; typedef long long LL; const int MAXN = 2e5;
int r[MAXN]; int main()
{
int flag = 1;
int n, o;
int pos = 1;
int res = 0;
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> o;
if (o == 1)
r[pos]++;
else
pos++;
if (i == 1 && o == 0)
flag = 0;
if (i == n && o == 0)
flag = 0;
res = max(res, r[pos]);
}
if (flag)
res = max(res, r[1] + r[pos]);
cout << res << endl; return 0;
}
Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest的更多相关文章
- Codeforces Round #547 (Div. 3) 题解
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...
- Codeforces Round #506 (Div. 3) C. Maximal Intersection
C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #198 (Div. 2) B. Maximal Area Quadrilateral
B. Maximal Area Quadrilateral time limit per test 1 second memory limit per test 256 megabytes input ...
- E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题
E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #547 (Div. 3) G 贪心
https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...
- Codeforces Round #547 (Div. 3) F 贪心 + 离散化
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...
- Codeforces Round #547 (Div. 3) D
http://codeforces.com/contest/1141/problem/D 题目大意: 鞋子匹配,用一个小写字母表示一种颜色.L[i]表示左脚的颜色,R[i]表示右脚的颜色,只有当L[i ...
- Codeforces Round #547 (Div. 3) D. Colored Boots
链接:https://codeforces.com/contest/1141/problem/D 题意: 给连个n长度的字符串. 求两个字符串相同字符对应位置的对数,并挨个打印. 字符:?可以代替任何 ...
- Codeforces Round #547 (Div. 3) A.Game 23
链接:https://codeforces.com/contest/1141/problem/A 题意: 给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m. 不能得到时为-1. ...
随机推荐
- template <typename T>模板类定义
#include "stdafx.h"#include "iostream"#include <ctime>using namespace std; ...
- jquery跨域3
这两天用 Jquery 跨域取数据的时候,经常碰到 invalid label 这个错误,十分的郁闷,老是取不到服务器端发送回来的 json 值, 一般跨域用到的两个方法为:$.ajax 和$.get ...
- bootStrap效果图
http://www.ziqiangxuetang.com/bootstrap/bootstrap-tutorial.html
- YoutubeAPI使用
YoutubeAPI使用 1 Youtube API能干什么 2 Youtube API 2.0 Youtube简介 2.1 如何使用Youtube API 2.1.1 获取Youtube 的开发 ...
- unittest执行测试用例的N种姿势总结
1.我们写几个方法,用来做测试用例 2.我们在另一文件中引用这个模块下面的所有类方法,先看第一种方法: 运行结果: 缺点:每个用例都需要加载到测试套件中,如果有1000个用例,要写1000次重复的代码 ...
- R文件报错
res中drawable中的资源文件进行命名时只能用0-9或者a-z或者-,其他的东西不能使用,也禁止在重命名时开头使用大写字母
- MTCNN人脸检测识别笔记
论文:Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks 论文链接:https:// ...
- java中关键字volatile的误解和使用
在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...
- Flutter实战视频-移动电商-13.首页_广告Banner组件制作
13.首页_广告Banner组件制作 主要是做这个小广告条. 其实就是读取一个图片做一个widget放到这里 使用stlessW快速生成 定义一个变量存放图片的url地址: 这样我们的广告条就写完了 ...
- Flutter实战视频-移动电商-29.列表页_商品列表数据模型建立
29.列表页_商品列表数据模型建立 简历数据模型 json生成dart类的网站: https://javiercbk.github.io/json_to_dart/ json数据 {",&q ...