Codeforces Round #390 (Div. 2)A Lesha and array splitting
来源:互联网 发布:数据的随机噪声 编辑:程序博客网 时间:2024/05/17 09:22
题目大意:
本质就是分组,不能使每组的和等于0,问要怎么分。
题目解法:
其实就是把每个0和之后的非0数结合就好。
代码:
#include "iostream"#include "algorithm"#include "cstdio"#include "math.h"#include "string"#include "string.h"using namespace std;int n, a[101], sum[101];int st[101], ed[101];int main(){while (scanf("%d", &n) != EOF) {bool flag = true;sum[0] = 0;int num = 0;for (int i = 1;i <= n;i++) {scanf("%d", &a[i]);if (a[i] == 0) {if (flag) {st[num] = i;flag = false;}}else {if (flag) {st[num] = ed[num] = i;num++;}else {ed[num] = i;num++;flag = true;}}}if (!flag&&num==0) {puts("NO");}else { puts("YES");printf("%d\n", num);for (int i = 0;i < num;i++) {if (i == num - 1) {printf("%d %d\n", st[i],n);}else {printf("%d %d\n", st[i], ed[i]);}}}} return 0;}
0 0
- A. Lesha and array splitting Codeforces Round #390 (Div. 2)
- Codeforces Round #390 (Div. 2)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 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
- Lesha and array splitting CodeForces
- A - Lesha and array splitting
- A. Lesha and array splitting
- 754A. Lesha and array splitting
- A. Lesha and array splitting----贪心
- codeforces-754A-Lesha and array splitting(简单分类处理)
- Codeforces Round #179 (Div. 1)-A. Greg and Array
- Codeforces Round #179 (Div. 1) A. Greg and Array
- Codeforces Round #440 (Div. 1) A. Maximum splitting
- 矩阵连乘
- [Shell]命令行选项解析
- 如何把一个website变为一个snap应用
- 关于vendor目录无法push到git问题
- S10.1_Struts2_FileUpload_Download 文件上传与下载
- Codeforces Round #390 (Div. 2)A Lesha and array splitting
- String 找重复数据
- Linux kernel启动流程简介
- Open Syllabus Project项目推荐——全美大学书籍喜好数据库
- Android项目模板化
- PAT(甲级)A+B in Hogwarts (20)
- PHP的轻量消息队列php-resque使用说明
- [Hadoop]数据复制DistCp
- CSS选择器速查表