cf754 A. Lesha and array splitting
应该是做麻烦了,一开始还没A(幸好上一次比赛水惨了)
#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 200005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>''){if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
int a[];
struct node{
int x,y;
}ans[];
int cnt;
int main()
{
int n=ra(),start=;
bool flag=;
for (int i=; i<=n; i++)
{
int x=ra();
if (x!=) a[i]=x,flag=;
}
if (!flag)
{
cout<<"NO";
return ;
}
cout<<"YES"<<endl;
if (a[]==)
{
for (int i=; i<=n; i++)
if (a[i]!=)
{
for (int j=i+; j<=n; j++)
if (a[j]!= || j==n)
{
ans[++cnt].x=;
ans[cnt].y=j-;
start=j;
break;
}
break;
}
int last=start;
for (int i=last; i<=n; i++)
{
if (i==n && a[i]==)
ans[cnt].y=n;
if (a[i]!=)
{
ans[++cnt].x=start;
ans[cnt].y=i;
start=i+;
}
}
}
else
{
int last=start;
for (int i=last; i<=n; i++)
{
if (i==n && a[i]==)
ans[cnt].y=n;
if (a[i]!=)
{
ans[++cnt].x=start;
ans[cnt].y=i;
start=i+;
}
}
}
cout<<cnt<<endl;
for (int i=; i<=cnt; i++)
cout<<ans[i].x<<" "<<ans[i].y<<endl;
return ;
}
cf754 A. Lesha and array splitting的更多相关文章
- Codeforces 754A Lesha and array splitting(简单贪心)
A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...
- Codeforces 754A Lesha and array splitting (搜索)
题目链接 Lesha and array splitting 设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可. #includ ...
- 【codeforces 754A】Lesha and array splitting
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #390 (Div. 2) A. Lesha and array splitting
http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...
- Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting 水题
C. Array Splitting You are given a sorted array
- CodeForces - 1175D Array Splitting(数组划分+后缀和+贪心)
You are given an array a1,a2,…,ana1,a2,…,an and an integer kk. You are asked to divide this array in ...
- D. Array Splitting(后缀数组)
You are given an array
- CF1175D Array Splitting
题目链接 题意 给出一个长度为\(n\)的序列\(a\),要求分为恰好\(K\)段.第\(i\)个点的贡献是\(a_i \times f(i)\),\(f(x)\)表示x所属的是第几段. 思路 非常巧 ...
- Codeforce 1175 D. Array Splitting
新鲜热乎的题 Codeforce 1175 D. 题意:给出一个长度为$n$的序列$a$,你需要把它划分为$k$段,每一个元素都需要刚好在其中一段中.分好之后,要计算$\sum_{i=1}^{n} ( ...
随机推荐
- UML和模式应用
引言 Applying UML and Patterns,以一个商店POS系统NextGen和一个掷骰子游戏Monopoly为例,围绕OOA/D的基本原则GRASP,以迭代作为基本方法.以UML为表达 ...
- 【英语】Bingo口语笔记(54) - how to date a foreigner
- python工厂方式创建list
>>> l = list('sdfsdf') >>> l ['s', 'd', 'f', 's', 'd', 'f']
- IOS设计模式之三(适配器模式,观察者模式)
本文原文请见:http://www.raywenderlich.com/46988/ios-design-patterns. 由 @krq_tiger(http://weibo.com/xmuzyq) ...
- 【加解密】关于DES加密算法的JAVA加密代码及C#解密代码
JAVA加密: package webdomain; import java.security.Key; import java.security.spec.AlgorithmParameterSpe ...
- 使用ncc分析代码
1 ncc是一个编译器, 用于输出程序的一些调用信息等, 可以查看函数调用关系, 支持函数指针, 查看数据结构和代码. 可以用来分析和理解代码. “" ... with ncc, in le ...
- pybombs 安装
参考:https://github.com/gnuradio/pybombs 先装:pip 然后: pip install PyBOMBS 更新源: pybombs recipes add gr-re ...
- Iframe的应用以及父窗口和子窗口的相互访问
点评:Iframe和FRAME的区别,方便大家以后在使用过程中根据实际需要取舍.- function getParentIFrameDocument(aID) { var rv = null; // ...
- hadoop2.5.2学习及实践笔记(二)—— 编译源代码及导入源码至eclipse
生产环境中hadoop一般会选择64位版本,官方下载的hadoop安装包中的native库是32位的,因此运行64位版本时,需要自己编译64位的native库,并替换掉自带native库. 源码包下的 ...
- PySpark操作HBase时设置scan参数
在用PySpark操作HBase时默认是scan操作,通常情况下我们希望加上rowkey指定范围,即只获取一部分数据参加运算.翻遍了spark的python相关文档,搜遍了google和stackov ...