$CF1141B Maximal Continuous Rest$
告诉你一天n件事情
a[i]为1是休息 a[i]为2是工作
求最长连续的休息时间(即最长的1
可以作为环状来求。(即环状最长的1
这题就可以用前缀和贪心等什么操作。。
然后用\(ans1ans2\)瞎搞
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() { LL res(0),f(1); register char c ;
while(isspace(c=getchar())) ; c == '-'? f = -1 , c = getchar() : f = 1 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ; return res * f ;
}
int n ;
int a[200000+5] ;
int cnt[200000+5] ;
int flag = 1 ;
int ans = 0 ;
int ans1 = 0 ;
int ans2 = 0 ;
signed main() {
n = In() ;
for(register int i=1;i<=n;i++) a[i] = In() ;//读入
for(register int i=1;i<=n;i++)
if(a[i]==1) cnt[i]=cnt[i-1]+1,ans1=max(ans1,cnt[i]);//求前缀和 即当前最长的1 ans1储存最大值
else {
if(flag) ans2+=(i-1),flag=0;//储存最前面的一段1
cnt[i]=0;
}
if(cnt[n]) ans = cnt[n] + ans2;//如果第n个位置有连在一起的。
//则数字为 cnt[n]+ans2
cout << max(ans,ans1) << endl ;//ans求的是序列中最大值。 ans是首尾环状。 要求的是最长的则取max
return 0 ;
}
随机推荐
- Boundary Conditions
test test Table of Contents 1. Boundary conditions 1.1. Neumann boudary condition vs Dirichlet BC 1. ...
- Ajax_数据格式_HTML
[数据格式提要] 1.在服务器端Ajax是一门与语言无关的技术.在业务逻辑层使用何种服务器端语言都可以. 2.从服务器端接收数据的时候,那些数据必须以浏览器能够理解的格式来发送.服务器端的编程语言只能 ...
- https://blog.csdn.net/zhi_sheng/article/details/78910082----mybatis写当天 当月的数据 时间段数据
https://blog.csdn.net/zhi_sheng/article/details/78910082---- mybatis写当天 当月的数据 时间段数据
- 纯JSP实现简单微信开发后台
%@ page import="java.net.*" % %@ page import="java.math.*" % %@ page import=&quo ...
- Linux下Ubuntu 操作系统 部署
1.1 先更新系统 环境 更新命令为: apt-get update 1.2 安装jdk 安装JDK命令为:sudo apt-get install o penjdk-7-jdk 1.3 安装tomc ...
- MyBatis3-SqlSessionDaoSupport的使用
以下内容引用自http://www.yihaomen.com/article/java/336.htm: 在MyBatis3中这个Mapper接口貌似充当了以前在iBatis2中的DAO层的作用.但事 ...
- uva 11212 - Editing a Book(迭代加深搜索 IDA*) 迭代加深搜索
迭代加深搜索 自己看的时候第一遍更本就看不懂..是非常水,但智商捉急也是没有办法的事情. 好在有几个同学已经是做过了这道题而且对迭代加深搜索的思路有了一定的了解,所以在某些不理解的地方询问了一下他们的 ...
- 21行python代码实现拼写检查器
引入 大家在使用谷歌或者百度搜索时,输入搜索内容时,谷歌总是能提供很好的拼写检查,比方你输入 speling,谷歌会立即返回 spelling. 前几天,看到http://norvig.com/spe ...
- 数据结构——算法之(027)( 在O(1)时间内删除链表结点)
[申明:本文仅限于自我归纳总结和相互交流,有纰漏还望各位指出. 联系邮箱:Mr_chenping@163.com] 题目:在O(1)时间内删除链表结点.且不知道链表头 题目分析: 1.把要删除节点的下 ...
- android自己定义之 5.0 风格progressBar
近期做项目,用到了ProgressBar .就想到了要使用Android5.0 的效果,就随手实现了一下. 效果图: 大概的思路: 1. 圆圈通过Canvas去绘制 2.圆圈的动画通过Animator ...