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

...

时间:2019-08-25 14:11:44      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:freopen   algo   lse   stream   ios   string   using   scan   name   

include

include

include

include

include

using namespace std;

define LL long long

const LL N = 2e5 + 100;

LL n, k, a[N], tot, ans;
bool vis[N], cnt[N];

inline void open_judge() {
freopen ("page.in", "r", stdin);
freopen ("page.out", "w", stdout);
}

int main() {
open_judge();
scanf("%lld%lld",&n,&k);
for(int i = 1 ; i <= n ; i++)
scanf("%lld",&a[i]);
for (int i = 1 ; i <= n ; i++) {
if (cnt[a[i]])continue;
else if (tot < k)++ans, ++tot, cnt[a[i]] = true;
else {
memset(vis, false,sizeof(vis));
LL pos;
for(int j = i + 1 ; j <= n ; j++) {
if (vis[a[j]] || !cnt[a[j]]) continue;
pos = j;
vis[a[j]] = true;
}
for(int k = 1 ; k <= i ; k++) {
if(cnt[a[k]] && ! vis[a[k]])pos = k;

        }
        ++ans; 
        cnt[a[pos]] = false; 
        cnt[a[i]] = true; 
    }
}
printf ("%lld\n", ans); 
system("pause");
return 0; 

}

...

标签:freopen   algo   lse   stream   ios   string   using   scan   name   

原文地址:https://www.cnblogs.com/Repulser/p/11407594.html

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