1895: 985的0-1串难题(好题)
2016-08-09 12:15
429 查看
1895: 985的0-1串难题
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 197 Solved: 51
SubmitStatusWeb
Board
Description
985有一个长度为n的0-1串,已知他最多可以修改k次(每次修改一个字符即0->1 或者 1->0),他想知道连续的全1子串最长是多少。Input
第一行输入一个整数t,代表有t组测试数据。每组数据第一行输入两个整数n,k分别代笔上面的信息。
注:1 <= t <= 12,1 <= n <= 100000,0 <= k <= 100000。
Output
一个整数代表可以得到的最大长度。Sample Input
26 30101006 2010100Sample Output
54很好的思维题,记录0的位置,找出符合条件最长的末位置减初位置就可以了.
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main ()
{
int dis[100010];
char s[100010];
int t,n,m;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
scanf("%s",s);
int p = 0,g = 0;
dis[p++] = 0;
for(int i=0; i<n; i++){
if(s[i] == '0'){
dis[p++] = i+1;
}
}
dis[p++] = n+1;
if(p-1 <= m){
printf("%d\n",n);continue;
}
else{
for(int i=m+1; i<p; i++){
g = max(g,dis[i]-(dis[i-(m+1)]+1));
}
printf("%d\n",g);
}
}
return 0;
}
相关文章推荐
- 1895: 985的0-1串难题
- zzulioj1895: 985的0-1串难题(思维)
- 1895: 985的0-1串难题
- 【郑轻】[1895]985的0-1串难题
- ZZULI OJ 1895: 985的0-1串难题
- zzuli 1895 985的0-1串难题
- ZZULIOJ/ 郑轻OJ 1895: 985的0-1串难题(数学思维)
- 郑轻 oj 1895: 985的0-1串难题
- 【zzulioj 1895 985的0-1串难题】
- ZZULI 1895: 985的0-1串难题
- zzuli oj1895: 985的0-1串难题 [二分]
- 【zzuliOJ】1895 - 985的0-1串难题(思维)
- zzuliOJ 1895: 985的0-1串难题 【二分】
- zzuli 1895: 985的0-1串难题(二分)
- 【多校训练】ZZULIOJ 1895 985的0-1串难题
- 【zzuli-oj】-1895-985的0-1串难题(思维,好)
- zzuliOJ 1895:985的0-1串难题(二分+打表)
- ZZuli oj 1895: 985的0-1串难题(二分+打表)
- zzuli 1895 (985的0-1串难题)
- 985的0-1串难题