MG loves gold
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 360 Accepted Submission(s): 196
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 with n golds.
It is known that the gold is a sequence with n golds.
Sample Input
2
5
1 1 2 3 -1
5
1 1 2 2 3
Sample Output
2
3
bestcoder93#的第一题,用set检查就好 因为至少要用一次所以计数K应该初始为1
中文题意 MG要挖矿,矿物的排列为从左到右的一串数列,数列中不同数值的元素代表不同种类的矿,他从左到右开始挖,每使用一把铲子挖的矿必须是不同种类的,否则需要换一把铲子再继续挖,直到所有矿都挖完为止,问MG总共使用了多少把铲子。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define N 1000000
const int mod = 1e9+7;
int main()
{
int T;
scanf("%d",&T);
while(T--) {
set<int> st;
int n;
scanf("%d",&n);
int x, k = 1;
for(int i = 0;i < n; i++) {
scanf("%d",&x);
if(st.count(x)) {
k++;
st.clear();
}
st.insert(x);
}
printf("%d\n",k);
}
return 0;
}