MG loves gold

 Accepts: 451
 Submissions: 1382
 Time Limit: 3000/1500 MS (Java/Others)
 Memory Limit: 262144/262144 K (Java/Others)
Problem Description

MG is a lucky boy. He is always be able to find gold from underground.

It is known that the gold is a sequence with nn elements, which has its own color CC.

MG can dig out a continuous area of sequence every time by using one shovel, but he's unwilling to dig the golds of the same color with one shovel.

As a greedy person, he wish to take all the n golds away with least shovel. The rules also require MG not to dig twice at the same position.

MG thought it very easy and he had himself disdained to take the job. As a bystander, could you please help settle the problem and calculate the answer?

Input

The first line is an integer TT which indicates the case number.(1<=T<=101<=T<=10)

And as for each case, there are 11 integer nn in the first line which indicate gold-number(1<=n<=1000001<=n<=100000).

Then there are nn integers CC in the next line, the x-th integer means the x-th gold’s color(|C|<=2000000000∣C∣<=2000000000).

Output

As for each case, you need to output a single line.

there should be one integer in the line which represents the least possible number of shovels after taking away all nn golds.

Sample Input
2
5
1 1 2 3 -1
5
1 1 2 2 3
Sample Output
2
3 题意:MG要挖矿,矿物的排列为从左到右的一串数列,数列中不同数值的元素代表不同种类的矿,他从左到右开始挖,每使用一把铲子挖的矿必须是不同种类的,否则需要换一把铲子再继续挖,直到所有矿都挖完为止,问MG总共使用了多少把铲子。
思路:可以用一个set集合来记录当前所使用的铲子已经挖的矿,从左到右扫描每一个矿,若当前的矿在集合set中找到,说明这块矿用旧铲子挖到过,得用新的铲子继续挖,此时清空集合,再用来记录新铲子已经挖到的矿。记录使用了几把铲子即可;
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
using namespace std;
typedef long long ll;
const int N_MAX = +;
int N;
ll A[N_MAX];
set<ll>s;
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &N);
for (int i = ; i < N; i++) {
scanf("%lld", &A[i]);
}
int res = , i = ; while (i < N) {
bool what = ;
s.insert(A[i]);
for (int j = i + ; j < N; j++) {
set<ll>::iterator it = s.find(A[j]);
if (it != s.end()) {//说明该元素出现过
i = j;//下次用新铲子的挖掘从当前j开始
what = ;
break;
}
else
s.insert(A[j]);
}
s.clear();
res++;
if (!what)break;//中途没被打断过,顺利挖到尾部
}
printf("%d\n",res);
}
return ;
}

best corder MG loves gold的更多相关文章

  1. (set)MG loves gold hdu6019

    MG loves gold Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  2. 【BestCoder Round #93 1001】MG loves gold

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=6019 [题意] 每次选择一段连续的段,使得这一段里面没有重复的元素; 问你最少选多少次; [题解] ...

  3. HDU 6019:MG loves gold(暴力set)

    http://acm.hdu.edu.cn/showproblem.php?pid=6019 题意:给出n个颜色的物品,你每次取只能取连续的不同颜色的物品,问最少要取多少次. 思路:从头往后扫,用se ...

  4. hdu 6020 MG loves apple 恶心模拟

    题目链接:点击传送 MG loves apple Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Ja ...

  5. 【HDU 6021】 MG loves string (枚举+容斥原理)

    MG loves string  Accepts: 30  Submissions: 67  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  6. 【HDU 6020】 MG loves apple (乱搞?)

    MG loves apple  Accepts: 20  Submissions: 693  Time Limit: 3000/1500 MS (Java/Others)  Memory Limit: ...

  7. hdu 6021 MG loves string

    MG loves string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others ...

  8. MG loves string

    MG loves string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others ...

  9. hdu 6021 MG loves string (一道容斥原理神题)(转)

    MG loves string    Accepts: 30    Submissions: 67  Time Limit: 2000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. 掉坑日志:Windows Native API与DPI缩放

    高DPI显示器越来越普及,软件自然也要适应这个变化,最近实习的时候也遇到了一个关于DPI缩放的问题.因为内部框架的一个控件有BUG,会导致内容的显示出问题,后来实在没办法改成了用Windows Nat ...

  2. 关于在vue 中使用百度ueEditor

    1. 安装  npm i vue-ueditor --save-dev 2.从nodemodels  取出ueditor1_4_3_3 这整个目录,放入vue 的 static 目录 3.配置 ued ...

  3. 使用虚拟环境来管理python的包

    1.背景 在开发python项目的过程中,我们会用到各种各样的包,我们使用pip来管理包,请看下图我们刚装好python解释器时已安装的包: 但是随着我们疯狂的使用pip install xxx后,系 ...

  4. 【AC自动机】bzoj3172: [Tjoi2013]单词

    fail图上后缀和需要注意一下 Description 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次. Input 第一个一个整 ...

  5. 【Python学习之五】高级特性5(切片、迭代、列表生成器、生成器、迭代器)

    5.迭代器 由之前的生成器可知,for循环用于可迭代对象:Iterable.包括集合数据类型: list.tuple.dict.set.str 等,以及两种生成器.判断迭代器,使用 isinstanc ...

  6. 如何用纯 CSS 创作一个极品飞车 loader

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/MBbEMo 可交互视频 ...

  7. Linux 用户管理切换用户su和提取命令sudo-visudu详解

    一.su --run a shell with substitute user and group IDs -,-l,--login make the shell a login shell, cle ...

  8. 【js】input 焦点到内容的最后

     //引用部分应支持jQuery  function find_focus(obj){    var curr = jQuery(obj);    var val = curr.val();    c ...

  9. selection problem-divide and conquer

    思路: 随机选取列表中的一个值v,然后将列表分为小于v的,等于v的,大于v的三组.对于k<=left.size()时, 在left中执行selection:落在中间的,返回v:k>left ...

  10. zoj 4054

    #define ll long long ; int t; ll ans,tmp; char s[N]; int main() { scanf("%d",&t); whil ...