CodeForces 754A Lesha and array splitting
来源:互联网 发布:视频音频切割软件 编辑:程序博客网 时间:2024/05/16 10:14
题目链接:http://codeforces.com/contest/754/problem/A
题意:给你一个长度为n的数组,让你把他划分成若干个任意长度的子序列,但是这个子序列的和不能为0,若不能划分就输出NO,否则输出YES,并输出子序列的区间个数,和区间
解析:一个非零数组为一个区间肯定是最方便的,然后0就跟最近的非零数抱团,所以从前往后扫,last初始为1,遇到非零数就更新为last+1,并记录答案
#include <bits/stdc++.h>using namespace std;const int maxn = 105;struct node{ int l,r; node() {} node(int _l,int _r) { l = _l; r = _r; }};int main(void){ int n; scanf("%d",&n); int last = 1; vector<node>ans; for(int i=1;i<=n;i++) { int x; scanf("%d",&x); if(x) { ans.push_back(node(last,i)); last = i+1; } } if(ans.size()) { puts("YES"); printf("%d\n",ans.size()); for(unsigned i=0;i<ans.size()-1;i++) printf("%d %d\n",ans[i].l,ans[i].r); printf("%d %d\n",ans[ans.size()-1].l,n); } else puts("NO"); return 0;}
0 0
- 【codeforces 754A】Lesha and array splitting
- Codeforces 754A - Lesha and array splitting
- codeforces 754 A Lesha and array splitting
- CodeForces 754A Lesha and array splitting
- Codeforces 754A Lesha and array splitting
- 754A. Lesha and array splitting
- Lesha and array splitting CodeForces
- A - Lesha and array splitting
- A. Lesha and array splitting
- A. Lesha and array splitting Codeforces Round #390 (Div. 2)
- Codeforces Round #390 (Div. 2)A Lesha and array splitting
- codeforces-754A-Lesha and array splitting(简单分类处理)
- A. Lesha and array splitting----贪心
- Codeforces Round #390(Div. 2)A. Lesha and array splitting【思维】
- Codeforces Round #390 (Div. 2) - A Lesha and array splitting (贪心)
- codeforces 299 A. Ksusha and Array
- codeforces 295A - Greg and Array
- CodeForces 295A Greg and Array
- ubuntu 下 mysql 插入中文
- 桥接模式
- 归一化(normalization)/标准化(standardization) 方法汇总
- ffmpeg推送RTSP直播流到EasyDarwin报错问题的修复
- Mysql 备份与恢复
- CodeForces 754A Lesha and array splitting
- ubuntu Linux 16.04下的护眼宝
- java编程的9个知识点
- java工程师进阶路线
- 延时3秒跳转错误页面
- LeetCode (Jump Game)
- Linux-wxpython3.0安装
- KMP算法:next数组变形
- 关于Android文件下载路径的坑