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. python-IE浏览器调用

    IE浏览器驱动添加 selenium官网有提供下载http://code.google.com/p/selenium/downloads/list 这里我用的是IEDriverServer_Win32 ...

  2. 如何使用公网ip访问部署在云服务器的web项目

    我使用的是华为云服务器,已经在服务器上部署好项目,现在想要通过外网访问服务器的话,需要配置一下安全组:1.依据下图找到安全组,点击教我设置: 2. 进入安全组配置示例,根据自己的需要选择不同的配置方案 ...

  3. matplotlib subplot 子图

    总括 MATLAB和pyplot有当前的图形(figure)和当前的轴(axes)的概念,所有的作图命令都是对当前的对象作用.可以通过gca()获得当前的axes(轴),通过gcf()获得当前的图形( ...

  4. poj 1328 安雷达问题 贪心算法

    题意:雷达如何放置?在xoy二维平面坐标系里面,x轴上方的为岛屿,x轴下方的是雷达要放到位置,如何放使得雷达放的最少? 思路 肯定放在x轴上减少浪费是最好的选择 什么情况下,雷达无法到达呢?--以这个 ...

  5. 关于.ascx

    .ascx用户控件  参考系列教程User controls in asp.net - Part 104 用户控件包含了html.代码和其他Web或者用户控件的组合,并在Web服务器上以自己的文件格式 ...

  6. Linux学习-登录档的轮替(logrotate)

    rsyslogd 利用的是 daemon 的方式来启动的, 当有需求的时候立刻就会被执行的,但是 logrotate 却是在规定的时间到了之后才来进行登录档的轮 替, 所以这个 logrotate 程 ...

  7. src与href的区别

    href: 是指向网络资源所在位置,建立和当前元素(锚点)或当前文档(链接)之间的链接,用于超链接. src:是指向外部资源的位置,指向的内容将会嵌入到文档中当前标签所在位置:在请求src资源时会将其 ...

  8. LA 4094 WonderTeam 构造

    题意: 一共有\(n\)支队伍参加比赛,每两支队伍比赛两场,主客场各一场. 胜场得\(3\)分,平局得1分,败场不得分. 一支得分为\(p\)的队伍的排名\(=\)分数大于\(p\)的队伍数\(+1\ ...

  9. django 修改urls.py 报错误:TypeError: view must be a callable or a list/tuple in the case of include().

    #coding=utf-8 from django.conf.urls import include,url from django.contrib import admin from blog im ...

  10. “玲珑杯”ACM比赛 Round #23

    A -- 生是脂肪的人 Time Limit:2s Memory Limit:128MByte Submissions:263Solved:97 DESCRIPTION 给定一个整数n,输出[(10^ ...