HDU 6022 MG loves set

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6022

题意:

解题思路:

贪心去做的,若当前要挖掘的颜色,在已经挖掘范围内,ans+1,否则就继续去挖下一个。

实现代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;

const int MAXN=100000000;
int a[MAXN];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        int ans=0;

        map<int,int>mp;
        mp.clear();
        for(int i=0;i<n;i++){
            if(mp[a[i]]==0)
                mp[a[i]]++;
            else{
                ans++;
                mp.clear();
                mp[a[i]]++;
            }
        }
        if(!mp.empty())
            ans++;
        cout<<ans<<endl;
    }
    return 0;
}

 

posted on 2017-04-05 11:17  mkfoy  阅读(335)  评论(0)    收藏  举报

导航