HDUoj -6019- MG loves gold (set

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.
 

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;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值