HDU 6019 MG loves gold
来源:互联网 发布:下载手机淘宝最新版 编辑:程序博客网 时间:2024/04/27 23:55
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 n elements, which has its own color C 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 T which indicates the case number.(1<=T<=10 1<=T<=10)
And as for each case, there are1 1 integer n n in the first line which indicate gold-number(1<=n<=100000 1<=n<=100000).
Then there aren n integers C C in the next line, the x-th integer means the x-th gold’s color(|C|<=2000000000 |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 alln n golds. Sample Input Sample Output
// BY T P
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?
And as for each case, there are
Then there are
there should be one integer in the line which represents the least possible number of shovels after taking away all
251 1 2 3 -151 1 2 2 3
23
#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<iostream>#include<set>using namespace std;int road[100005];void getans(int n){set<int>set1;int ans = 0;for (int i = 0; i < n; i++){if (!set1.empty()){if (set1.count(road[i])){ans++;set1.clear();set1.insert(road[i]);continue;}else{set1.insert(road[i]);}}else{set1.insert(road[i]);}}ans += 1;cout << ans << endl;}int main(){int t;scanf("%d", &t);while (t--){int n;scanf("%d", &n);for (int i = 0; i < n; i++){scanf("%d", &road[i]);}getans(n);}return 0;}
// BY T P
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
- 源码开发
- 测试导出exp及imp选项filesize
- Get started with Docker 中文文档(1)——Part 1: Orientation and Setup
- uva 222 The Department of Redundancy Department
- [LeetCode.542]01 Matrix
- HDU 6019 MG loves gold
- 2017.4.22考试
- 大数据分析:孩子早已变了,身为父母的你却没跟上
- angular.element
- 音视频同步播放器遇到的奇葩的bug
- java_web 学习记录(九):jdbcpool + datasource
- 特殊矩阵之对称矩阵
- 【面试题】剑指Offer-48-不能被继承的类
- Mybatis中in查询的一个小问题