HDU 6019 MG loves gold

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 n 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 <dl><dd> 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 are 1 1 integer n n in the first line which indicate gold-number( 1<=n<=100000 1<=n<=100000).

Then there are n n integers C C in the next line, the x-th integer means the x-th gold’s color( |C|<=2000000000 |C|<=2000000000). </dd> Output <dd> 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 all n n golds. </dd> Sample Input <dd>
2
5
1 1 2 3 -1
5
1 1 2 2 3
</dd> Sample Output <dd>
2
3
#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 </dd></dl>
全部评论

相关推荐

开发转测第二人:没实习的话,两个项目吧,八股也要准备一下,这个时间点有点小晚了
点赞 评论 收藏
分享
02-12 20:22
重庆大学 Java
字节暑期刚入职四天,因为是年前,所以很多正职都放假走了,也就没有给我分配mt,然后有一个老哥在我来的时候给我发了一个landing手册,然后还有关于部门业务的白皮书,还有一些业务代码。然后本人是java面的,进来第一次接触go语言&nbsp;前面几天熟悉了一下go的语法和go的框架,可以读但是还不太会写,然后业务白皮书也看的很头疼,包括landing手册里要了解的很多东西说实话我看文档真的快看死了,一个嵌套一个,问题是我还完全不知道咋用这个我了解的东西,还有就是那个项目代码,那个老哥喊我去写写单测,熟悉一下go的语法,但也进行的很困难(这是我第一段实习,之前都是springboot那一套,真不太熟悉这个)想问问大家的建议,就是我从现在开始到在开年回来之前应该做些什么,我目前就一个想法&nbsp;就是复现一个landing手册上的go框架小项目&nbsp;就是相当于帮自己锻炼锻炼怎么写go&nbsp;或者各位大佬有没有更好的锻炼go语法的建议还有就是大家都在说vibe&nbsp;coding,那我应该怎么锻炼自己使用ai的能力,感觉我除了给一些需求然后它给我生成代码,好像就没别的用法了,那些什么工作流、拆解、skill啥的都不知道从哪一个地方开始,包括我现在正在实习,不知道精力该怎么分配,去网上想找找关于agent开发的一些学习流程,说实话,众说纷纭,有的是从python开始打基础然后系统学那些rag&nbsp;prompt&nbsp;langchain&nbsp;mcp等等,有的是说直接找一个github上的ai项目然后反复问ai,我确实有点迷茫,恳求各位大佬能留下你们宝贵的建议,我一定认真反复深刻学习有一说一&nbsp;我觉得字节饭挺好吃的!
Jasonnnnnn...:直接把项目代码喂给AI然后让它帮你分析,如果组里已经有一些流程图总结的话最好,没有的话自己画一个 Go的话其实只要把基础语法搞明白就行了,项目里很多都是直接让ai帮你写好然后自己稍微改下,不用学的特别深 ai的话,可以自己写一些md文件来搞点小东西,但除非你打算转算法,否则不用把rag langchain学的特别深,了解下就行了
字节跳动公司福利 1371人发布
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务