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} ( ...
随机推荐
- eclipse 报错 import ... cannot be resolved 处理方法
项目上右键,properties, 找java build path,切到libraies标签,将爆红的jdk编辑一下,选用你需要的jdk版本,一般1..我看你类的httpServlet报错,也是这个 ...
- spring整合各大ORM框架的原理图
- java动态代理复习
package com.free.testProxy; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Met ...
- mysql 表空间及索引的查看方法
CONCAT : concat() 方法用于连接两个或多个数组. database : 数据库(11张) 数据库,简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件 ...
- Android 多进程编程 15问15答!
ps:阅读本文 需要对android 多进程编程有一定了解. 1.Android中总共有几种方式进行IPC? 答:一共有两种,一种是binder 还有一种是socket.Binder 大家用的比较多. ...
- Android 轻量级ORM数据库开源框架ActiveAndroid 源码分析
ActiveAndroid 项目地址在https://github.com/pardom/ActiveAndroid 关于他的详细介绍和使用步骤 可以看下面两篇文章: https://github.c ...
- 纠结的ARC
xcode不断进步,在xcode4中引入了ARC的概念.您用或者不用它就在那里,于是有了本文:如何在未使用arc的工程中引入一个使用了arc特性的文件,如何在arc工程中引用未使用arc的文件.其实说 ...
- 嵌入式 使用mp4v2将H264+AAC合成mp4文件
录制程序要添加新功能:录制CMMB电视节目,我们的板卡发送出来的是RTP流(H264视频和AAC音频),录制程序要做的工作是: (1)接收并解析RTP包,分离出H264和AAC数据流: (2)将H26 ...
- jQuery插件开发的模式和结构
jQuery插件开发 一般来说,jQuery插件的开发分为两种:一种是挂在jQuery命名空间下的全局函数,也可称为静态方法:另一种是jQuery对象级别的方法,即挂在jQuery原型下的方法,这样通 ...
- Enter回车切换输入焦点方法兼容各大浏览器
做项目时,客户要求能够用enter回车直接切换输入(焦点),当最后一个时候,直接提交信息. 第一想法就是,网上去copy一段代码直接用.但了百度.谷歌找了个遍,找到的代码80%以上都是一样的.有的代码 ...