HDU
来源:互联网 发布:plc称重模块怎样编程 编辑:程序博客网 时间:2024/06/06 17:12
MG loves gold
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 985 Accepted Submission(s): 422
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水题,一次取一串数组,数组元素不重复,问最少取几次一开始使用流输入输出超时,后来改到scanf和printf#include <iostream>#include<cstring>#include<stdio.h>#include<algorithm>#include<set>using namespace std;int main(){ int N; scanf("%d",&N); while(N--) { int n,ans=1; scanf("%d",&n); if(n==0) { printf("0\n"); continue; } set<int>myset; while(n--) { int t; scanf("%d",&t); if(myset.count(t)==1) { ans++; myset.erase(myset.begin(),myset.end()); } myset.insert(t); } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 文本框 光标 跳
- 私有云”共享“
- BZOJ 4236: JOIOJI
- postfix+mysql(数据库对邮件的管理)
- jquery.validate的使用,注册验证
- HDU
- 1166: 判断升序
- 面向对象(一):对象属性
- 图的存储结构
- 【Shader基础篇】之纹理
- Polya原理的应用经典实例
- 阿牛的EOF牛肉串
- 复习
- Zookeeper注册中心和Dubbo-Admin管理平台的搭建 http://blog.csdn.net/chinahuyong/article/details/69567840