Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row
- 题意:一个3e5范围的序列;要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能出现一次。
策略:
- 延伸:这里指的延伸如当发现1…1如果以最后出现重叠的数为右边界则就表示左延伸,若以1.0.1..0第二个0前一个位置作为右边界就为右延伸;
- 开始时想是右延伸,考虑到可能只出现一组两个数相同,认为向左延伸会出错,但是直接WA了之后,发现这并不是题目的坑点(其实只需将最后一组改成左右延伸就可以了),给一组数据就知道向右延伸是错误的:
数据: n = 5, 1 1 0 0 1若是右延伸,则为 【1 1 0】,后面0 1不能配对,其实这里就直接说明了只要存在两个数相同,就不会出现无解的情况; - 左延伸,一遇到里面还存有这个数据,直接往l[],R[]里面存区间,当然l是以上一个r为左边界的;最火一组数据让右边界等于n即可;
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5;
set<int> Set;
int L[MAXN],R[MAXN];
int main()
{
int i,n,x,l = 1,cnt = 0;
cin>>n;
for(i = 1;i <= n;i++){
scanf("%d",&x);
if(Set.count(x)){
L[++cnt] = l;
R[cnt] = i;
l = i + 1;
Set.clear();
}else Set.insert(x);
}
if(cnt == 0) return puts("-1"),0;
R[cnt] = n;
printf("%d\n",cnt);
for(i = 1;i <= cnt;i++)
printf("%d %d\n",L[i],R[i]);
}
Educational Codeforces Round 6 C. Pearls in a Row的更多相关文章
- Educational Codeforces Round 6 C. Pearls in a Row set
C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- QT下自定义QQ聊天窗口tab控件
1.用继承pushbutton派生类来实现tab按钮,里面加一个QPushbutton关闭按钮:(自定义类:CCustomTabButton) 2.多个tab按钮用QHboxLayout做容器: 3. ...
- Android动态加载技术初探
一.前言: 现在,已经有实力强大的公司用这个技术开发应用了,比如淘宝,大众点评,百度地图等,之所以采用这个技术,实际上,就是方便更新功能,当然,前提是新旧功能的接口一致,不然会报Not Found等错 ...
- 理解URI和URL
1)定义: URI: Uniform Resource Identifier,通用资源标识符 ---是一个用于标识某一互联网资源名称的字符串(by 维基百科) URL:Uniform Resource ...
- arcgis 获得路径和环境变量信息
import arcpy import sysimport osimport string reload(sys) sys.setdefaultencoding("utf8")sc ...
- Import user's Environment path into Linux cron task
How to use "cron" to create scheduled task Minimum time cycle: 1 minute Use crontab -e edi ...
- JS 时间与时间戳的相互转换
<script type="text/javascript"> var time = "2015-04-22 21:41:43";//2015-4- ...
- C#微信公众号开发 -- (七)自定义菜单事件之VIEW及网页(OAuth2.0)授权
通俗来讲VIEW其实就是我们在C#中常用的a标签,可以直接在自定义菜单URL的属性里面写上需要跳转的链接,也即为单纯的跳转. 但更多的情况下,我们是想通过VIEW来进入指定的页面并进行操作. 举一个简 ...
- 那天有个小孩跟我说LINQ(一) 转载
1 LINQ准备(代码下载) 新建项目 linq_Ch1控制台程序,新建一个Entity文件夹 1.1 对象初始化器 在Entity新建一个类Student,代码如下 using S ...
- 在office 2010中插入Mathtype出现ctrl+v不能复制的问题
加载项中去掉command for那个即可 详细网址:http://heblue.blog.163.com/blog/static/96325568201375102628405/
- flexpaper 开源轻量级的在浏览器上显示各种文档的组件
FlexPaper是一个开源轻量级的在浏览器上显示各种文档的组件,被设计用来与PDF2SWF一起使用, 使在Flex中显示PDF成为可能,而这个过程并无需PDF软件环境的支持.它可以被当做Flex的库 ...