Codeforces Round #390 (Div. 2) A. Lesha and array splitting
http://codeforces.com/contest/754/problem/A
题意:
给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0。
思路:
先统计一下不为0的数,只要有一个不为0的数,那么就能分割。
如果一个数不为0,则让它单独成为一组,如果它后面有0,则把它后面的连续的0也归到这一组中。
特别要注意一下的是,序列一开始就是0的情况。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn=+; int n;
int a[maxn]; struct node
{
int l, r;
}ans[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
int cnt=;
for(int i=;i<=n;i++)
scanf("%d",&a[i]); for(int i=;i<=n;i++)
if(a[i]!=) cnt++; if(cnt==) {puts("NO");continue;} int i=;
cnt=;
while(i<=n)
{
ans[cnt].l=i;
while(a[i]==) i++;
while(i<n && a[i+]==) i++;
ans[cnt].r=i;
i++;
cnt++;
} puts("YES");
printf("%d\n",cnt);
for(int i=;i<cnt;i++)
{
printf("%d %d\n", ans[i].l, ans[i].r);
}
}
return ;
}
Codeforces Round #390 (Div. 2) A. Lesha and array splitting的更多相关文章
- Codeforces Round #390 (Div. 2)
时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing ...
- Codeforces Round #390 (Div. 2) A+B+D!
A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)
http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory ...
- Codeforces Round #390 (Div. 2) A
One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into sev ...
- Codeforces Round #390 (Div. 2) E(bitset优化)
题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果 (超出的部分循环处理) 一种做法是使用fft,比较难写,所以没有写 这里使用一个暴力的做法,考虑到一共只出现26个字符 所以使用一 ...
- Codeforces Round #390 (Div. 2) A B C D
这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...
- Codeforces Round #390 (Div. 2) D
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring s ...
- Codeforces Round #390 (Div. 2) B
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. ...
随机推荐
- 【BZOJ4545】DQS的trie 后缀自动机+LCT
[BZOJ4545]DQS的trie Description DQS的自家阳台上种着一棵颗粒饱满.颜色纯正的trie. DQS的trie非常的奇特,它初始有n0个节点,n0-1条边,每条边上有一个字符 ...
- Windows系统下做定时任务为Oracle数据库每天自动备份
1.创建备份目录d:\backup, 创建批处理命令Bak.bat,编写备份脚本 ? 1 2 exp user/passwd@orcl DIRECT=Y BUFFER=100000 FILE=D:\b ...
- Oracle HA 之 RAC one node实战
--创建rac one node步骤 安装grid软件,配置grid集群:安装oracle软件:dbca创建rac one node. >试验创建的rac one node数据库信息如下: gl ...
- Constructor Overloading in Java with examples 构造方法重载 Default constructor 默认构造器 缺省构造器 创建对象 类实例化
Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Cl ...
- a Javascript library for training Deep Learning models
w强化算法和数学,来迎接机器学习.神经网络. http://cs.stanford.edu/people/karpathy/convnetjs/ ConvNetJS is a Javascript l ...
- sshd:root@notty解决方法
sshd:root@notty解决方法 [复制链接]--http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=2050551 cat /e ...
- iptables 执行清除命令 iptables -F 要非常小心的
iptables 执行清除命令 iptables -F 要非常小心的 http://blog.csdn.net/netingcn/article/details/5692972 使用 /sbin/ip ...
- 205-react SyntheticEvent 事件
参看地址:https://reactjs.org/docs/events.html
- makefile中ifeq与ifneq dev/null和dev/zero简介 dd命令
ifeq语法是ifeq "<arg1>;" "<arg2>;" ,功能是比较参数“arg1”和“arg2”的值是否相同,相同时为1 i ...
- 使用scikit-learn 估计器分类
本章的几个概念: 估计器(estimator) 用于分类.聚类和回归分析 转换器(transformer):用于数据预处理回来数据转换 流水线(pipeline): ...