ACMA
来源:互联网 发布:java实现qq第三方登录 编辑:程序博客网 时间:2024/06/16 04:26
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
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<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;}
1 0
- ACMA
- HDU ACMA 1025 最小递增序列, 二分
- 杭电ACMA + B Problem II问题解析
- apk的更新和下载安装
- 鼠标悬停商品图片,图片放大,并且可拖动
- ubuntu apache下设置隐藏index.php
- linux 串口通信-配置与实例
- EJB解释
- ACMA
- 阿里云服务器上搭建Discuz论坛
- 二分的技巧
- Android Java 并发程序系列----你应该知道的多线程概念
- java移位运算
- 面向机器学习专家的 MNIST 高级教程代码
- 【GDSOI2017第三轮模拟】Informatics Training(码农,平衡树)
- python文件和目录操作方法大全
- Linux (常用命令2)