Codeforces Round #380 (Div. 2,) D - Sea Battle

题意:n,a,b,k,字符串长度,a条船,每条船长度,之前有k个射击次数,字符串0代表未知,1代表射击的位置且是没有船的,问至少射击几次能射到一条船,和输出位置

思路:根据0的数量我们知道最多可以有多少条船,然后-1-1-1-1,直到数量变成a-1,那么肯定之前射击的肯定有一条船

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=2e5+10;
 4 
 5 char s[N];
 6 int c[N];
 7 int main(){
 8     int n,a,b,k;
 9     scanf("%d%d%d%d",&n,&a,&b,&k);
10     scanf("%s",s+1);
11     int l=0,sum=0;
12     for(int i=1;i<=n;i++){
13         if(s[i]=='0'){
14             sum++;
15             if(sum==b){
16                 c[++l]=i;sum=0;
17             }
18         }
19         else sum=0;
20     }
21     printf("%d\n",l-a+1);
22     for(int i=1;i<=l-a+1;i++){
23         printf("%d ",c[i]);
24     }
25 }

 

posted on 2017-08-14 14:37  hhhhx  阅读(116)  评论(0)    收藏  举报

导航