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 ;
}

最新文章

  1. 通过3个Hello World应用来了解ASP.NET 5应用是如何运行的(3)
  2. [BZOJ 2819]Nim
  3. Python自动化 【第十二篇】:Python进阶-MySQL和ORM
  4. 【C#】【MySQL】C# 查询数据库语句@Row:=@Row+1
  5. grep -w
  6. Vi问题
  7. frame和iframe区别
  8. Android应用程序的安装位置
  9. Problem 2169 shadow
  10. 如何让其他电脑访问到自己的Django项目
  11. 怎样从外网访问内网CouchDB数据库
  12. react ES5 与ES6的写法
  13. JMeter压力测试及服务器状态监控教程
  14. SourceTree 的初次使用的两个小问题
  15. 配置Hadoop1.2.1
  16. 解题:CF949D Curfew
  17. Web安全学习笔记——SQL注入
  18. form表单注册——HTML
  19. MySQL在本机无法基于localhost访问的问题解决
  20. Golang 线程池

热门文章

  1. Sublime Text 3配置Minify压缩,格式化css,js,html,json,svg
  2. 从零打造在线网盘系统之Struts2框架核心功能全解析
  3. Google Now &#39;not available in your country&#39;
  4. OGG双向复制
  5. Oracle AWR之-enq: TX - allocate ITL entry
  6. spring boot web服务
  7. Python爬虫实例(五) requests+flask构建自己的电影库
  8. 4.windows如何导入python包
  9. windoes下一台电脑是无线/USB上网,如何将另一台电脑通过一拖一上网
  10. Winform 下使用WebBrowser的HTML编辑控件—WinHtmlControl 在win7 IE9下的问题