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. LODOP 获取打印设计代码不带INIT初始化语句

    前面的博文生成JS代码模版和文档式模版,生成的是带初始化语句的模版,如果想要打印多个,可以循环多个任务,什么是一个任务,可查看本博客相关博文:Lodop打印语句最基本结构介绍(什么是一个任务)一个任务 ...

  2. Thread的其他属性方法

    from threading import Thread,currentThread,active_count import time def task(): print('%s is running ...

  3. Linux命令归纳

    Linux基本命令 Linux Xshell远程连接 ssh 用户名@id地址 例如: ssh root@192.168.11.53 增加类指令 创建文件夹 mkdir 文件名 mkdir -p 路径 ...

  4. docker-安装技巧

    使用官方脚本安装 curl -fsSL "https://get.docker.com/" | sh 使用yum 安装是可以查看版本 yum list docker-ce.x86_ ...

  5. [IOI2018]机械娃娃——线段树+构造

    题目链接: IOI2018doll 题目大意:有一个起点和$m$个触发器,给出一个长度为$n$的序列$a$,要求从起点出发按$a$的顺序经过触发器并回到起点(一个触发器可能被经过多次也可能不被经过), ...

  6. 复习 LIS nlogn

    参考:https://www.cnblogs.com/wxjor/p/5524447.html 最长下降只要把符号都倒过来就行 在栈中二分找第一个比当前值小的替换就行

  7. Pfsense2.34中文版

    Pfsense2.34中文版 来源  https://forum.netgate.com/topic/112076/pfsense2-34%E4%B8%AD%E6%96%87%E7%89%88-%E8 ...

  8. 搭建gogs常见问题

    1.无法连接ssh,显示connection refuse. 原因是“custom/conf/app.ini”没有开启ssh功能,改为以下配置就行了  START_SSH_SERVER = true ...

  9. MT【250】距离0-7

    是否存在一个正方体,它的8个顶点到某一个平面的距离恰好为$0,1,2,3,4,5,6,7$ ?若存在指出正方体与相应的平面的位置关系.不存在说明理由. 分析:设平面$\alpha$的单位法向量为$\o ...

  10. 「2017 Multi-University Training Contest 2」2017多校训练2

    1001 Is Derek lying 题目链接 HDU6045 Is Derek lying? 给出两个人选择题的回答,问得分分别为x和y是否可能.(\(1\le N \le 80000,0\le ...