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. Egret Wing4.1.0 断点调试

    一  双击代码行号左侧打断点 二 选择调试视图工具栏. 三  点击开始调试 1 wing内置播放器调试 选择此项进行调试会打开Egret内置播放器,我这里这个版本该选项无法进行断点... 2 使用本机 ...

  2. 【Android】TextView动态设置android:drawableLeft|Right|Top|Bottom,SetColor

    Android中有时需动态设置控件四周的drawble图片,这个时候就需要调用 setCompoundDrawables(left, top, right, bottom),四个参数类型都是drawa ...

  3. 问答项目---用户注册的那些事儿(JS验证)

    做注册的时候,由于每一个页面都有都要可以注册,可以把注册方法写到一个公用的方法里去,其他方法继承这个方法: 简单注册JS示例: <script type='text/javascript'> ...

  4. 试验性的Numpy教程(译)

    Python中Numpy模块学习: 转自:http://my.oschina.net/u/175377/blog/74406

  5. phpStorm 显示行号

  6. Oracle下where子句

    课外题 要求:删除某一个用户,同时保留该用户的数据?如何解决 alter user scott account lock :改天需要使用则解锁unlock 锁定用户使用sysdba登录还是可以查看数据 ...

  7. CodeForces 19D Points (线段树+set)

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  8. Mysql覆盖索引与延迟关联

    延迟关联:通过使用覆盖索引查询返回需要的主键,再根据主键关联原表获得需要的数据.   为什innodb的索引叶子节点存的是主键,而不是像myisam一样存数据的物理地址指针? 如果存的是物理地址指针不 ...

  9. mysql 数据操作 单表查询 having 过滤 练习

    1. 查询各岗位内包含的员工个数小于2的岗位名.岗位内包含员工名字.个数 mysql> select post,group_concat(name),count(id) from employe ...

  10. loadrunner11的移动端性能测试之结果分析

    测试步骤之结果分析器(Analysis) 进入Analysis 当场景停止运行后,可从Controller中进入.点击[Results]—[Analysis Results]见下图: 若想打开一个已保 ...