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

Codeforces Round #426 (Div. 2)B. The Festive Evening

时间:2017-07-31 13:28:40      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:space   color   codeforce   for   main   log   模拟   set   记录   

题意:有26个城门,k个守卫,给出每个城门人进入的顺序,只有当这个城门进入的人是最后一个,该城门的守卫才能去别的城门,问是否有个时间段,守卫不够用

思路:记录起始,模拟下

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int l[30],r[30];
 5 int b[30];
 6 
 7 int main(){
 8     int n,m; string s;
 9     cin>>n>>m;
10     cin>>s;
11     for(int i=s.size()-1;i>=0;i--){
12         if(r[s[i]-A]==0) {
13              r[s[i]-A]=i;
14         }
15 
16     }
17     memset(l,-1,sizeof(l));
18     for(int i=0;i<s.size();i++){
19         if(l[s[i]-A]==-1){
20             l[s[i]-A]=i;
21         }
22 
23     }
24 
25     int Max=0;
26     for(int i=0;i<s.size();i++){
27 
28         if(l[s[i]-A]==i){
29             Max++;
30             if(Max>m) {
31                 cout<<"YES"<<endl;return 0;
32             }
33         }
34         if(r[s[i]-A]==i){
35             Max--;
36         }
37         if(Max>m) {
38                 cout<<"YES"<<endl;return 0;
39             }
40 
41     }
42     cout<<"NO"<<endl;return 0;
43 }

 

Codeforces Round #426 (Div. 2)B. The Festive Evening

标签:space   color   codeforce   for   main   log   模拟   set   记录   

原文地址:http://www.cnblogs.com/hhxj/p/7262467.html

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