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. 规范化Normalization

    一.批规范化 Batch Normalization 转自: http://blog.csdn.net/hjimce/article/details/50866313    https://zhuan ...

  2. ASP.Net Post方式获取数据流的一种简单写法

    public static string PostWebReq(string PostUrl, string ParamData, Encoding DataEncode)        {      ...

  3. WC2019游记 && 课件

    WC2019 游记 课件 wc2019.zip_免费高速下载|百度网盘-分享无限制 提取码: un6z day 0 打飞机去广州... 在飞机上刷了爱乐(le)之城, 相当好看... 广二好大! 哈三 ...

  4. linq之group by 的使用

    group by var list = from s in _sysBll.GetList(s => s.ParamID == "TraSchType" && ...

  5. form-layui

    html <div id="formData"> <form class="layui-form formBtn" style="m ...

  6. HTML元素类别及转换

    位置特性分类元素分为三类:块级元素,行内元素,行级块元素 1.块级元素(block)        特点: (1)可以设置宽高.内.外边距:               (2)独占一行(即前后均有换行 ...

  7. jenkins运行脚本生成HTML报告时遇到的问题

    1.jenkins生成HTML报告 1)安装插件:HTML Publisher plugin 2)系统管理->插件管理->安装HTMLHTML Publisher plugin 2.job ...

  8. shopNC 拓扑图

    shopNC :

  9. Linux 源码安装 Python3

    下载源码包https://www.python.org/downloads/ 解压(以3.64版本为例)wget https://www.python.org/ftp/python/3.6.4/Pyt ...

  10. Ubuntu相关配置

    1.Ubuntu配置root密码 2.开机ssh连接--nat   编辑网络设置端口转发