码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 6019:MG loves gold(暴力set)

时间:2017-05-05 21:44:56      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:lov   int   span   log   fine   can   pid   its   题意   

http://acm.hdu.edu.cn/showproblem.php?pid=6019

题意:给出n个颜色的物品,你每次取只能取连续的不同颜色的物品,问最少要取多少次。

思路:从头往后扫,用set存之前取了什么物品,然后每次重复就clear,ans++。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define N 100010
 4 int c[N];
 5 set<int> se;
 6 
 7 int main() {
 8     int t; scanf("%d", &t);
 9     while(t--) {
10         int n; scanf("%d", &n); se.clear();
11         for(int i = 1; i <= n; i++) scanf("%d", &c[i]);
12         int ans = 0;
13         for(int i = 1; i <= n; i++) {
14             if(se.count(c[i]))
15                 ans++, se.clear();
16             se.insert(c[i]);
17         }
18         if(!se.empty()) ans++;
19         printf("%d\n", ans);
20     }
21     return 0;
22 }

 

HDU 6019:MG loves gold(暴力set)

标签:lov   int   span   log   fine   can   pid   its   题意   

原文地址:http://www.cnblogs.com/fightfordream/p/6814944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!