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. Python——管道通信

    管道:双向通信 2个进程之间相互通信 from multiprocessing import Pipe,Process def func(conn1,conn2): conn2.close() whi ...

  2. layui tips

  3. 设置和安装 BizTalk Server 2016 的必备组件

    设置服务器,然后安装和配置软件必备组件. 加入本地管理员组       若要安装并配置 BizTalk Server,在本地计算机上使用管理员帐户登录到服务器. 向本地管理员组添加任何管理 BizTa ...

  4. Nginx tcp限制并发、IP、记日志

    L:114 Syntax: limit_conn_zone key zone=name:size;//类似http limit_conn 需要开个共享内存  zone=name(共享内存名称):siz ...

  5. CentOS 安装git

    git安装 yum install git 初始化git “git init --bare 文件夹” 添加所有 “git add . ” 提交 “git commit -m "提交信息&qu ...

  6. redis日常使用汇总--持续更新

    redis日常使用汇总--持续更新 工作中有较多用到redis的场景,尤其是触及性能优化的方面,传统的缓存策略在处理持久化和多服务间数据共享的问题总是不尽人意,此时引入redis,但redis是单线程 ...

  7. python成长之路一

    1,计算机基础 CPU:中央处理器,相当于人类的大脑,运算中心,控制中心. 内存:暂时储存数据,与CPU交互,8G,16G,32G,64G § 优点:读取速度快. § 缺点:容量小,造价高,断电即消失 ...

  8. 牛客寒假算法训练1 D 欧拉(容斥)

    1 #include<bits/stdc++.h> using namespace std; ; typedef long long ll; int p[maxn],a[maxn]; ll ...

  9. 【XSY2779】最小表示串 KMP DP polya定理

    题目描述 给你一个字符串\(s\),问你有多少个串是最小表示串且字典序\(\leq s\) \(|s|\leq 1000\) 题解 先把\(s\)变成比\(s\)小的最大的最小表示串.方法是从后枚举每 ...

  10. 【dfs】P1331 海战

    题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...