【BestCoder Round #93 1001】MG loves gold

【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=6019

【题意】

每次选择一段连续的段,使得这一段里面没有重复的元素;
问你最少选多少次;

【题解】

从第一个元素开始一直选就好;
不能选了就把之前的记忆清除掉;
然后重新开始选;重新记忆选过哪些元素;
写个map就好.

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define ref(x) scanf("%lf",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;

int T;
map <int, int> dic;

int main()
{
    //freopen("F:\\rush.txt", "r", stdin);
    rei(T);
    while (T--)
    {
        dic.clear();
        int n;
        rei(n);
        int num = 1;
        rep1(i, 1, n)
        {
            int x;
            rei(x);
            if (dic[x])
            {
                dic.clear();
                num++;
            }
            dic[x] = 1;
        }
        printf("%d\n", num);
    }
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
posted @ 2017-10-04 18:45  AWCXV  阅读(217)  评论(0编辑  收藏  举报