题目:http://codeforces.com/problemset/problem/620/C

文章末有一些测试数据仅供参考

题目大意

给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对儿相等的数字,每个数字都属于某个部分,输出划分的部分数量以及对应区间。

 思路

很简单一道题,输入的数据都不用存的,输入一个检测一个就好了,用map打标记,用容器存一下要输出的区间端点值,最后挨个儿输出就好了

代码如下:

#include<iostream>
#include<map>
#include<vector>
#include<cstdio>
using namespace std;
long long item;
vector<int> V;
int main()
{
int N;
map<long long, bool> P;
while (cin >> N)
{
P.clear(), V.clear();
V.push_back();
for (int i = ; i <= N; ++i)
{
scanf("%I64d", &item);
if (P[item])
{
V.push_back(i);
if (i != N) //如果是最后一个的话就不用放后面的了
V.push_back(i + );
P.clear();
}
else P[item] = ;
}
int size_ = V.size() / * ; //可能会出现奇数(有前无后)
if (!size_) //5:1 2 3 4 5 这种输出为-1情况
{
cout << - << endl;
continue;
}
if (V[size_- ] != N)
V[size_-] = N;
cout << V.size() / << endl;
for (int i = ; i < size_; i += )
cout << V[i] << " " << V[i + ] << endl;
}
}

测试数据:

Input:


Output:


感谢您的阅读,祝您生活愉快~

Pearls in a Row CodeForces 620C 水题的更多相关文章

  1. 【Codeforces自我陶醉水题篇~】(差17C code....)

    Codeforces17A 题意: 有一种素数会等于两个相邻的素数相加 如果在2~n的范围内有至少k个这样的素数,就YES,否则就NO; 思路: 采用直接打表,后面判断一下就好了.那个预处理素数表还是 ...

  2. CodeForces 327B 水题。

    I - 9 Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. Codeforces - 631B 水题

    注意到R和C只与最后一个状态有关 /*H E A D*/ struct node2{ int kind,las,val,pos; node2(){} node2(int k,int l,int v,i ...

  4. 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 ...

  5. CodeForces 620C Pearls in a Row

    水题,每当出现重复就分割开来,最后留下的尾巴给最后一段 #include<cstdio> #include<cstring> #include<cmath> #in ...

  6. 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 ...

  7. 【32.26%】【codeforces 620C】Pearls in a Row

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  9. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

随机推荐

  1. 25、LinkedList特有方法

    LinkedList特有方法 public void addFirst(E e)及addLast(E e) public E getFirst()及getLast() public E removeF ...

  2. c# 生成随机N位数字串(每位可以重复)

    /// <summary> /// 生成随机数字窜 /// </summary> /// <param name="Digit">位数</ ...

  3. AutoCAD DevTV-AUTOCAD二次开发资源合集

    Webcast Language Date AutoCAD .Net - Session 2 English 13-Sep-12 AutoCAD .Net - Session 1 English 6- ...

  4. Linux Kernel sys_call_table、Kernel Symbols Export Table Generation Principle、Difference Between System Calls Entrance In 32bit、64bit Linux【转】

    转自:http://www.cnblogs.com/LittleHann/p/4127096.html 目录 1. sys_call_table:系统调用表 2. 内核符号导出表:Kernel-Sym ...

  5. docker stack 部署 redis

    =============================================== 2019/4/16_第2次修改                       ccb_warlock 更新 ...

  6. 28 Data Race Detector 数据种类探测器:数据种类探测器手册

    Data Race Detector 数据种类探测器:数据种类探测器手册 Introduction Usage Report Format Options Excluding Tests How To ...

  7. Kaggle案例分析1--Bestbuy

    1. 引言 Kaggle是一个进行数据挖掘和数据分析在线竞赛网站, 成立于2010年. 与Kaggle合作的公司可以提供一个数据+一个问题, 再加上适当的奖励, Kaggle上的计算机科学家和数据科学 ...

  8. 【鬼脸原创】JQuery获取元素的方法总结

    目录 一.说明 二.获取本身 三.获取同级元素 四.获取父级元素 五.获取子级元素 一.说明   获取元素的方法分为两种:jQuery选择器.jQuery遍历函数. 做个总结,巩固下知识. 二.获取本 ...

  9. JSP和Servlet那些事儿系列--HTTPS

    原文:http://qingkangxu.iteye.com/blog/1614053 <JSP和Servlet那些事儿 >系列文章旨在阐述Servlet(Struts和Spring的MV ...

  10. 洛谷P1411 砝码称重

    传送门啦 这个题总体思路就是先搜索在 $ dp $ void dfs(int keep,int now){ //使用 放弃 if(now > m) return; //已经放弃超过m个了,就退出 ...