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的更多相关文章

  1. Codeforces Round #390 (Div. 2)

    时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing ...

  2. Codeforces Round #390 (Div. 2) A+B+D!

    A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...

  3. Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)

    http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #390 (Div. 2) E(bitset优化)

    题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果 (超出的部分循环处理) 一种做法是使用fft,比较难写,所以没有写 这里使用一个暴力的做法,考虑到一共只出现26个字符 所以使用一 ...

  7. Codeforces Round #390 (Div. 2) A B C D

    这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...

  8. Codeforces Round #390 (Div. 2) D

    All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring s ...

  9. 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. ...

随机推荐

  1. linux下安装F-prot杀毒软件

    一. f-prot的安装 1.首先我们要创建一个带有超级权限的用户 sudo passwa root 2.su 切换用户 3.下载F-prot http://www.f-prot.com/downlo ...

  2. 精简的webservice

    看了网上好多关于webservice的例子,基本上对初学者来说都是模棱两可云里雾里,现在,我将网上关于webservice的讲解提炼出来,通过一个最简单使用并且方便的例子,告诉大家什么是webserv ...

  3. linux时间与Windows时间不一致的解决

    一.首先要弄清几个概念:1. “系统时间”与“硬件时间” 系统时间: 一般说来就是我们执行 date命令看到的时间,linux系统下所有的时间调用(除了直接访问硬件时间的命令)都是使用的这个时间.   ...

  4. Object 对象有哪些方法?

    这个不看还真不一定能说全,请养成良好的阅读源码和JDK文档的习惯. 总结一下:一共11个,wait的3个+notify的2个,hashCode和equals还有toString共3个,然后clone和 ...

  5. 您好,python的请求es的http库是urllib3, 一个请求到贵司的es节点,想了解下,中间有哪些网关啊?冒昧推测,贵司的部分公共网关与python-urllib3的对接存在异常?

    您好,python的请求es的http库是urllib3, 一个请求到贵司的es节点,想了解下,中间有哪些网关啊?冒昧推测,贵司的部分公共网关与python-urllib3的对接存在异常? 负载均衡( ...

  6. python tensorflow keras

    pip install tensorflow pip install keras pip install theano http://www.open-open.com/lib/view/open14 ...

  7. appfog 使用

    1.需要安装ruby 和 devkit The RubyInstaller Development Kit (DevKit) is a MSYS/MinGW based toolkit than en ...

  8. mysql 约束条件介绍

     mysql 约束条件介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性主要分为: PRIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FO ...

  9. 用nginx的反向代理机制解决前端跨域问题在nginx上部署web静态页面

    用nginx的反向代理机制解决前端跨域问题在nginx上部署web静态页面 1.什么是跨域以及产生原因 跨域是指a页面想获取b页面资源,如果a.b页面的协议.域名.端口.子域名不同,或是a页面为ip地 ...

  10. Java8新特性(转载)

    1.Lambda表达式 Lambda表达式(也称为闭包)是整个Java 8发行版中最受期待的在Java语言层面上的改变.使用 Lambda 表达式可以使代码变的更加简洁紧凑. Lambda允许把函数作 ...