MG loves gold (map)
来源:互联网 发布:php点赞效果代码 编辑:程序博客网 时间:2024/04/28 05:52
MG loves gold
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 131 Accepted Submission(s): 80
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
思路:给出一个数字序列,求最少能分成多少个连续的不包含相同数字的子序列。因为数据范围较大,需要用map。
#include<cstdio>#include<iostream>#include<cstring>#include<map>using namespace std;int a[100005];map<int, int> mp;int main(){int cases, i, j, n, cnt;cin>>cases;while(cases--){cin>>n;cnt = 1;mp.clear();for(i = 0; i < n; i++){scanf("%d", &a[i]);if(mp[a[i]]){cnt++;mp.clear();mp[a[i]] = 1;}mp[a[i]] = 1;}cout<<cnt<<endl;}return 0;}
0 0
- MG loves gold (map)
- HDU6019 MG loves gold
- MG loves gold
- Best Coder MG loves gold
- HDOJ6019 MG loves gold 题解
- HDU 6019 MG loves gold
- HDU 6019 MG loves gold
- hdoj 6019 MG loves gold
- hdu 6019 MG loves gold
- HDU-6019 MG loves gold
- 【BestCoder Round #93】HDU6019 MG loves gold
- 【BestCoder Round #93】HDU6019 MG loves gold
- HDUoj -6019- MG loves gold (set
- BestCoder Round #93 MG loves gold hdu 6019
- HDU6020 MG loves apple
- HDU6021:MG loves string(思维 & 容斥)
- HDU 6020 MG loves apple
- HD6019MG loves gold
- nginx: [emerg] invalid number of arguments in "user" directive in /usr/local/nginx/conf/nginx.conf:5
- python3文本读取与写入常用代码
- BP神经网络 -- 详细教程
- 欧几里得算法
- Android App 性能优化方案
- MG loves gold (map)
- Java使用占位符拼接字符串
- [LintCode]Maximum Average Subarray
- nyoj 17 单调递增最长子序列(dp---记忆化搜索||穷举|| nlogn算法)
- 指向常量对象的指针 和 常量指针 区别
- DatePickerDialog主题问题
- java OOP 类和对象
- 半数集
- Note On <High Performance JavaScript>