CodeForces 620C Pearls in a Row
水题,每当出现重复就分割开来,最后留下的尾巴给最后一段
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=*+;
map<int,int>m;
int n;
int a[maxn];
struct X
{
int l,r;
};
vector<X>ans; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
m.clear();
int FinalRight=-;
int left=,right=;
for(int i=;i<=n;i++)
{
if(m[a[i]]==)
{
m.clear();
FinalRight=i;
X seg;
seg.l=left;
seg.r=i;
ans.push_back(seg);
left=i+;
}
else
{
m[a[i]]=;
right=i;
}
}
if(ans.size()==) printf("-1\n");
else
{
ans[ans.size()-].r=n;
printf("%d\n",ans.size());
for(int i=;i<ans.size();i++)
printf("%d %d\n",ans[i].l,ans[i].r);
}
return ;
}
CodeForces 620C Pearls in a Row的更多相关文章
- CodeForces - 620C Pearls in a Row 贪心 STL
C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces C. Pearls in a Row map的应用
C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- cf 620C Pearls in a Row(贪心)
d.有一串数字,要把这些数字分成若干连续的段,每段必须至少包含2个相同的数字,怎么分才能分的段数最多? 比如 是1 2 1 3 1 2 1 那么 答案是 21 34 7 即最多分在2段,第一段是1~3 ...
- Codeforces 620C EDU C.Pearls in a Row ( set + greed )
C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from ...
- 【32.26%】【codeforces 620C】Pearls in a Row
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- 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 ...
- C. Pearls in a Row
C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF620C Pearls in a Row
CF620C Pearls in a Row 洛谷评测传送门 题目描述 There are nn pearls in a row. Let's enumerate them with integers ...
随机推荐
- TextUtils
/** * 计算关键字在文本中出现的次数 * @param text * @param key * @return */ public static int count(String text, St ...
- Java中Date和Calender类的使用方法
查看文章 Java中Date和Calender类的使用方法 2009-10-04 20:49 Date和Calendar是Java类库里提供对时间进行处理的类,由于日期在商业逻辑的应用中占据着 ...
- UIWebView 使用要注意的几点
UIWebView 使用要注意的几点 最近有客户希望将移动端统一使用HTML5来完成,在iOS端就要用到UIWebView.遇到了以下三个主要问题: 加载HTTPS页面 不像Safari可以弹出弹框问 ...
- lucene索引合并与增量索引
利用 Lucene,在创建索引的工程中你可以充分利用机器的硬件资源来提高索引的效率.当你需要索引大量的文件时,你会注意到索引过程的瓶颈是在往磁盘上写索引文件的过程中.为了解决这个问题, Lucene ...
- jz2440 环境搭建遇到的问题
已解决:
- 【PDF单页转化为图片输出 注意:英文或图片类的PDF可转化,中文抛异常】
public static void main(String[] args) throws IOException { /** * PDF单页转化为图片输出 注意:英文或图片类的PDF可转化,中文抛异 ...
- 一个opencv 博客 大量文章(老版本编写C )
http://blog.csdn.net/Augusdi/article/category/747412
- js所有函数集合
lick() 对象.click() 使对象被点击. closed 对象.closed 对象窗口是否已关闭true/false clearTimeout(对象) 清除已设置的setTimeout对象 c ...
- AutoMapper使用简单总结
近期,在用AutoMapper整理一些模型对象映射,顺便小结一下使用的体会.难免有写得不对的地方,谢谢指出! 1. AutoMapper是一个.NET的对象映射工具,可以方便地进行对象间的赋值处理. ...
- opentsdb
http://blog.javachen.com/2014/01/22/all-things-opentsdb.html http://blog.csdn.net/bingjie1217/articl ...