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. JS 原型和闭包

    原文:深入理解javascript原型和闭包(完结) JavaScript 中的难点和重要点,排除知识体系之外的 bug.本篇是学习笔记,记录个人理解. 一.一切皆对象:一切(引用类型)都是对象,对象 ...

  2. Pulse-per-second (PPS) Signal Interfacing

    Some radio clocks and related timekeeping gear have a pulse-per-second (PPS) signal that can be used ...

  3. git 回退版本

    回滚到指定的版本 git reset --hard e377f60e28c8b84158 强制提交 git push -f origin master

  4. Luogu5205 【模板】多项式开根(NTT+多项式求逆)

    https://www.cnblogs.com/HocRiser/p/8207295.html 安利! 写NTT把i<<=1写成了i<<=2,又调了一年.发现我的日常就是数组开 ...

  5. springboot 简单搭建

    springboot的入门请参考:https://blog.csdn.net/hanjun0612/article/details/81538449 这里就简单看下搭建: 一,看一下项目结构: 创建一 ...

  6. [踩过的坑]Elasticsearch.Net 官网示例的坑

    经过昨天的ElasticSearch 安装,服务以及可以启动了,接下来就可以开发了,找到了官网提供的API以及示例,Es 官方提供的.net 客户端有两个版本一个低级版本: [Elasticsearc ...

  7. Chrome不安装插件实现页面长截图

    1.打开需要截图的页面,按F12进入审查模式 或直接在页面右击鼠标右键-检查,打开如下窗口 2.在控制台中按下 ctrl+shift+p,弹出如下输入框  3.输入screen进行模糊查找,选择“Ca ...

  8. Flask 构建微电影视频网站(一)

    Flask构建电影视频网站 Python MTV模型 Flask微内核 Flask扩展插件配置及使用方法 根据业务开发网站前后台功能 Flask结合MySQL数据库 你将可以独立开发网站 独立部署运维 ...

  9. IDEA调试技巧之条件断点

    调试的时候,在循环里增加条件判断,可以极大的提高效率,心情也能愉悦.以下介绍下IDEA使用条件[Condition]断点的方法 1.编写一段样例代码 /** * @author jiashubing ...

  10. Jdk1.6编译,1.7执行,1.7中没有需要的类,为何不会报错

      今天发现一个非常奇怪的问题   import sun.misc.BASE64Decoder; 我在本地引入了jdk1.6中的包,编译也用1.6没问题,但是实际上jdk1.7并没有这个包.在Linu ...