uestc 1904
#include<stdio.h>
#define N 1010
int min[N];
int main() {
int t,n,p,ti,first,end,num,i,j,max,k;
char s[N];
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&p);
first=1;
ti=0;
scanf("%s",s);
i=0;num=0;
while(s[i]!='1'&&i<n)
i++;
if(i==n) {
printf("0\n");
continue;
}
i++;
min[first]=0;
end=1;max=0;k=0;
for(j=i;j<n;j++) {
ti++;
if(s[j]=='1')
min[++end]=ti;
else
if(s[j]=='2'){
if(first<=end) {
while(min[first]+p<ti&&first<=end)
first++;
if(first<=end) {
num+=2;
first++;
}
}
}
while(min[first]+p<ti+1&&first<=end)
first++;
if(num+end-first+1>=max)
max=num+end-first+1;
}
ti++;
while(first<=end) {
if(min[first]+p>=ti)
k++;
first++;
}
if(num+k>max)
max=num+k;
printf("%d\n",max);
}
return 0;
}
uestc 1904的更多相关文章
- ACM:UESTC - 649 括号配对问题 - stack
UESTC - 649 括号配对问题 Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu ...
- UESTC 1015 Lweb and pepper --前,后缀最值
题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...
- UESTC 1852 Traveling Cellsperson
找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...
- UESTC 1851 Kings on a Chessboard
状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...
- UESTC 30 最短路,floyd,水
最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Statu ...
- jquery TypeError: 'undefined' is not a function (evaluating 'elem.nodeName.toLowerCase()') [jquery.js:1904]错误原因
今天,某个环境报了个js错误,TypeError: 'undefined' is not a function (evaluating 'elem.nodeName.toLowerCase()') [ ...
- 【wikioi】1904 最小路径覆盖问题(最大流+坑人的题+最小路径覆盖)
http://wikioi.com/problem/1904/ 这题没看数据的话是一个大坑(我已报告官方修复了),答案只要求数量,不用打印路径...orz 最小路径覆盖=n-最大匹配,这个我在说二分图 ...
- Poj 1904 King's Quest 强连通分量
题目链接: http://poj.org/problem?id=1904 题意: 有n个王子和n个公主,王子只能娶自己心仪的公主(一个王子可能会有多个心仪的公主),现已给出一个完美匹配,问每个王子都可 ...
- uestc oj 1218 Pick The Sticks (01背包变形)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 给出n根木棒的长度和价值,最多可以装在一个长 l 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...
随机推荐
- bzoj 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛【bfs】
满脑子dp简直魔性 模拟题意bfs转移即可 #include<iostream> #include<cstdio> #include<queue> using na ...
- bzoj 2015: [Usaco2010 Feb]Chocolate Giving【spfa】
因为是双向边,所以相当于两条到1的最短路和,先跑spfa然后直接处理询问即可 #include<iostream> #include<cstdio> #include<q ...
- react hooks 全面转换攻略(二) react本篇剩余 api
useCallback,useMemo 因为这两个 api 的作用是一样的,所以我放在一起讲; 语法: function useMemo<T>(factory: () => T, d ...
- 怎样去思考问题 解决问题 zkc学长的福利
题目描述 又是一年ACM集训的时刻,zkc学长邀请n位同学来玩一个有奖游戏.首先,他让每个同学在左.右手上面分别写下一个整数,zkc学长自己也在左.右手上各写一个整数.然后,让这n位同学排成一排,zk ...
- 题解报告:hdu 1686 Oulipo(裸KMP)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- Android 性能优化(24)*性能工具之「Traceview,dmtracedump」Profiling with Traceview and dmtracedump :记录并查看函数调用栈*
Profiling with Traceview and dmtracedump In this document Traceview Layout Traceview工具界面介绍 T ...
- 数据传递-------ajaxJson------spring3mvc中使用ajax传json中文乱码解决
参考来源:http://blog.csdn.net/dangerous_fire/article/details/25904225 第一种解决方法,适用所有情况 因为在controller中返回jso ...
- 实现div左右上下都居中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Pyhton TestCase运行闪退与失败,原因不详。。。
把源码贴上来,希望某位大神可以指点迷津: """Unit test for odbchelper.py This program is part of "Div ...
- 如何让不同浏览器调用不同的CSS样式
如何让不同浏览器调用不同的CSS样式 由 于对W3C标准支持程度的不同,往往导致同一个CSS样式表在各种Web浏览器中的呈现大相径庭.以目前市场占有率最高的两个浏览器Microsoft Interne ...