MG loves gold
Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1607    Accepted Submission(s): 659
 
 
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 n elements, which has its own color C.
 
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 T which indicates the case number.(1<=T<=10)
 
And as for each case, there are 1 integer n in the first line which indicate gold-number(1<=n<=100000).
 
Then there are n integers C in the next line, the x-th integer means the x-th gold’s color(|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 n golds.
 
Sample Input
2
5
1 1 2 3 -1
5
1 1 2 2 3
 
Sample Output
2
3
 
#include <iostream> //就是碰上相同的金坷垃就换铁锹。
#include <cstdio>
#include <set>
using namespace std;
int main()
{
int T;
long long a;
set<int> s;
scanf("%d",&T);
while(T--)
{
int n,sum=1;
scanf("%d",&n);
s.clear();
for(int i=0;i<n;i++)
{
scanf("%d",&a); //少点用数组,可能会超时。
if(s.count(a))
{
sum++;
s.clear();
}
s.insert(a);
}
cout<<sum<<endl;
}
return 0;
}
 
 

(set)MG loves gold hdu6019的更多相关文章

  1. best corder MG loves gold

    MG loves gold  Accepts: 451  Submissions: 1382  Time Limit: 3000/1500 MS (Java/Others)  Memory Limit ...

  2. 洛谷 P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold)

    P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold) 就像人类喜欢跳格子游戏一样,FJ的奶牛们发明了一种新的跳格子游戏.虽然这种接近一吨的笨拙的动物玩跳格子游戏几 ...

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

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

  4. [USACO13DEC]假期计划(黄金)Vacation Planning (gold)

    题目翻译不好,这里给出一份 题目背景 Awson是某国际学校信竞组的一只大佬.由于他太大佬了,于是干脆放弃了考前最后的集训,开车(他可是老司机)去度假.离开学校前,他打开地图,打算做些规划. 题目描述 ...

  5. Codeforces Round #254 (Div. 2) B (445B)DZY Loves Chemistry

    推理可得终于结果为2的(n-可分组合数)次方. 问题是怎么求出可分组合数,深搜就可以,当然并查集也能够. AC代码例如以下: 深搜代码!!! #include<iostream> #inc ...

  6. Luogu P3120 [USACO15FEB]牛跳房子(金)Cow Hopscotch (Gold)

    题目传送门 这是一道典型的记忆化搜索题. f[x][y]表示以x,y为右下角的方案数. code: #include <cstdio> #define mod 1000000007 usi ...

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

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

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

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

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

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

随机推荐

  1. 三、checkedListBoxControl

    一.checkedListBoxControl的使用全选 private void InitDate() { CheckedListBoxItem[] itemArr = { new CheckedL ...

  2. Tembin

    1:组织机构和用户之间是多对一的关系,一个组织结构可以有多个成员,一个成员只能属于一个组织机构. 2:app里面的邀请成员:是邀请发送短信通知用户注册tembin账户,当用户去注册的时候下面就会显示所 ...

  3. hdu 4578 Transformation 线段树多种操作裸题

    自己写了一个带结构体的WA了7.8次 但是测了几组小数据都对..感觉问题应该出在模运算那里.写完这波题解去对拍一下. 以后线段树绝不写struct!一般的struct都带上l,r 但是一条线段的长度确 ...

  4. [西安交大附中集训] d6 删边(cip)

    B. 删边(cip.cpp/in/out 1S/256M) 题面 给出一个没有重边和自环的无向图,现在要求删除其中两条边,使得图仍然保持连通. 你的任务是计算有多少组不合法的选边方案.注意方案是无序二 ...

  5. JarvisOJ Basic 熟悉的声音

    两种元素,还有声音,想到了莫尔斯电码,解码得到 jbluwewnz 提交,发现不对,觉得应该是有实际意义的东西,实在想不到还能怎么解,就去看了题解. 发现这个还可以再套一个凯撒密码,就拿python写 ...

  6. 最简单的socket服务器与客户端

    服务器: //服务器 #include <stdio.h> #include <netinet/in.h> #include <unistd.h> #include ...

  7. LVS负载均衡群集

    概述 群集的类型:无论是哪种服务器,都至少包括两台节点服务器,而对外表现为一个整体,只提供一个访问入口(域名或IP地址),相当于一台大型计算机.根据群集所针对的目标差异,可以分为以下三个类型: 1.负 ...

  8. BZOJ4519[Cqoi2016]不同的最小割——最小割树+map

    题目描述 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成 两个部分,如果结点s,t不在同一个部分中,则称这个划分是关于s,t的割.对于带权图来说,将 所有顶点处在 ...

  9. ElasticHD Windows环境下安装

    ElasticHD Linux环境下安装教程        ElasticHD windows环境下安装教程   习惯了T-SQL 查询,Elasticsearch的DSL查询语法简直就是反人类呀,一 ...

  10. SSM 即所谓的 Spring MVC + Spring + MyBatis 整合开发。

    SSM 即所谓的 Spring MVC + Spring + MyBatis 整合开发.是目前企业开发比较流行的架构.代替了之前的SSH(Struts + Spring + Hibernate) 计划 ...