$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 ;
}
随机推荐
- https报错注销源文件内容
open -a pycharm /Users/vivi/Library/Python/3.6/lib/python/site-packages/requests/packages/urllib3/co ...
- rsync+sersync自动同步备份数据
一.为什么要用Rsync+sersync架构?1.sersync是基于Inotify开发的,类似于Inotify-tools的工具2.sersync可以记录下被监听目录中发生变化的(包括增加.删除.修 ...
- java中List遍历删除元素-----不能直接 list.remove()
https://blog.csdn.net/github_2011/article/details/54927531 这是List接口中的方法,List集合调用此方法可以得到一个迭代器对象(Itera ...
- 好不容易帮同事写的一个awk,要记下来
给昌哥写的过滤的东东. 是实现了,但感觉丑,不规范. 记得下先. 原始数据格式: -- :: [ pool--thread-: ] - [ DEBUG ] origin match ::, user: ...
- [codevs 1482]路线统计(矩阵乘法)
题目:http://codevs.cn/problem/1482/ 分析:很像“经过K条边的最短路径条数”.但有所不同,那就是不是边数固定,而是路径总长度固定.看似不能用矩阵乘法了……但注意到每条边的 ...
- - > 网络流(【最大流】草地排水模板题)
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在农夫约翰的农场上,每 ...
- innodb-internals
https://www.pythian.com/blog/exposing-innodb-internals-via-system-variables-part-1-memory/
- 奇偶数对调,保持顺序 —— 剑指Offer
这道题目 https://www.nowcoder.net/practice/beb5aa231adc45b2a5dcc5b62c93f593?tpId=13&tqId=11166&t ...
- Codeforces 91C Ski Base 加边求欧拉回路数量
题目链接:点击打开链接 题意: 给出n个点m条无向边的图 開始图里没有边.每次加一条边,然后输出图里欧拉回路的条数. 思路: We will count the number of ski bases ...
- swift 2.0语法 元组
import UIKit /*: 元祖 * 可以将多个值保存在一起 * 格式: (数值1, 数值2, 数值3) * 特点: 元祖可以保存不同数据类型的值 * 用途: 在C/OC中如果一个函数想返回多个 ...