hdu 6019 MG loves gold
来源:互联网 发布:怎样推广网络棋牌 编辑:程序博客网 时间:2024/04/28 10:46
点击打开链接
MG loves gold
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1527 Accepted Submission(s): 629
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 withn 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?
It is known that the gold is a sequence with
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 are1 integer n in the first line which indicate gold-number(1<=n<=100000 ).
Then there aren integers C in the next line, the x-th integer means the x-th gold’s color(|C|<=2000000000 ).
And as for each case, there are
Then there are
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 alln golds.
there should be one integer in the line which represents the least possible number of shovels after taking away all
Sample Input
251 1 2 3 -151 1 2 2 3
Sample Output
23
刚开始题意理解错了,以为求最少可以改变顺序,但真正的意思是按顺序挖金子,遇到相同的换一把铲子,看代码吧
#include<stdio.h>#include<set>using namespace std;int main(){ set<int>gold; gold.clear(); int t; scanf("%d",&t); while(t--) { int c,n,sum=0; scanf("%d",&n); while(n--) { scanf("%d",&c); if(gold.find(c)!=gold.end()) { sum++; gold.clear(); gold.insert(c); } else gold.insert(c); } printf("%d\n",sum+1); gold.clear(); } return 0;}
阅读全文
0 0
- HDU 6019 MG loves gold
- HDU 6019 MG loves gold
- hdu 6019 MG loves gold
- HDU-6019 MG loves gold
- hdoj 6019 MG loves gold
- BestCoder Round #93 MG loves gold hdu 6019
- HDUoj -6019- MG loves gold (set
- HDU6019 MG loves gold
- MG loves gold
- Best Coder MG loves gold
- MG loves gold (map)
- HDOJ6019 MG loves gold 题解
- 【BestCoder Round #93】HDU6019 MG loves gold
- 【BestCoder Round #93】HDU6019 MG loves gold
- HDU 6020 MG loves apple
- hdu 6020 MG loves apple //bc Round #93 1002
- hdu 6021 MG loves string 子集 容斥 循环节
- HDU6020 MG loves apple
- Perl中use和require用法对比
- 最新版multer1.3.0上传文件
- Android四大图片缓存(Imageloader,Picasso,Glide,Fresco)原理、特性对比
- redis报告书(redisRepo.java)应该可以帮助到大家
- Android5.0+(CollapsingToolbarLayout)可折叠得展开的布局
- hdu 6019 MG loves gold
- 搭建本地 Registry
- 2017.05.24回顾 mysql添加索引
- 代码添加脚本 删除脚本
- win7 64位纯净版系统c盘空间显示与实际占用空间不对的解决方法图文教程
- 解决Gradle插件在eclipse或打包时不及时更新缓存的问题
- 时间复杂度与空间复杂度的基本概念
- 【poj 2492】A Bug's Life (带权并查集)
- shell脚本中传输传递问题分析