ACMA - MG loves gold
2017-04-22 16:07
323 查看
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
nn
elements, which has its own color
CC.
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?
InputThe first line is an integer
TT
which indicates the case number.(1<=T<=101<=T<=10)
And as for each case, there are
11
integer nn
in the first line which indicate gold-number(1<=n<=1000001<=n<=100000).
Then there are nn
integers CC
in the next line, the x-th integer means the x-th gold’s color(|C|<=2000000000|C|<=2000000000).OutputAs 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
nn
golds.Sample Input
Sample Output
23
It is known that the gold is a sequence with
nn
elements, which has its own color
CC.
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?
InputThe first line is an integer
TT
which indicates the case number.(1<=T<=101<=T<=10)
And as for each case, there are
11
integer nn
in the first line which indicate gold-number(1<=n<=1000001<=n<=100000).
Then there are nn
integers CC
in the next line, the x-th integer means the x-th gold’s color(|C|<=2000000000|C|<=2000000000).OutputAs 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
nn
golds.Sample Input
2 5 1 1 2 3 -1 5 1 1 2 2 3
Sample Output
23
#include<iostream> #include<string.h> #include<algorithm> #include<math.h> #include<stdio.h> #include<stack> #include<set> using namespace std; int main() { int t,n; while (~scanf("%d",&t)) { while (t--) { set<int>q; scanf("%d", &n); int sum = 1; int a; for (int i = 0; i < n; i++) { scanf("%d", &a); if (q.count(a)) { q.clear(); q.insert(a); sum++; } else { q.insert(a); } } printf("%d\n", sum); } } return 0; }
相关文章推荐
- hdoj 6019 MG loves gold
- HDU-6019 MG loves gold
- HDU6019 MG loves gold
- HDU 6019 MG loves gold
- HDU - 6019 ——MG loves gold
- hdu 6019 MG loves gold
- MG loves gold (map)
- best corder MG loves gold
- HDOJ6019 MG loves gold 题解
- 【BestCoder Round #93 1001】MG loves gold
- HDUoj -6019- MG loves gold (set
- 【BestCoder Round #93】HDU6019 MG loves gold
- HDU 6019 MG loves gold
- 【BestCoder Round #93】HDU6019 MG loves gold
- 【HDU 6021】 MG loves string (枚举+容斥原理)
- HDU6021 MG loves string 【容斥定理】
- hdu 6020 MG loves apple 恶心模拟
- HDU - 6020 MG loves apple (贪心+思维+模拟)
- hdu 6021 MG loves string 子集 容斥 循环节
- 【BestCoder Round #93】hdu6020 MG loves apple