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 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...
随机推荐
- P1128 [HNOI2001]求正整数
传送门 rqy是我们的红太阳没有它我们就会死 可以考虑dp,设\(dp[i][j]\)表示只包含前\(j\)个质数的数中,因子个数为\(i\)的数的最小值是多少,那么有转移方程 \[f[i][j]=m ...
- lodop 打印
使用Lodop打印: 一.在官网下载http://www.lodop.net/download.html 若是安装还是提示未安装,就按转这个 二.准备两个js 三.需要在页面最上面加入 <htm ...
- P2973 [USACO10HOL]赶小猪
跟那个某省省选题(具体忘了)游走差不多... 把边搞到点上然后按套路Gauss即可 貌似有人说卡精度,$eps≤1e-13$,然而我$1e-12$也可以过... 代码: #include<cst ...
- git 详细部署及其应用
第1章 版本控制系统 自动生成备份.随时回滚.知道改动的地方. 1.1 svn和git的区别 1.1.1 svn 集中式的版本控制系统,只有一个中央数据仓库,如果中央数据库仓库挂了或者不可访问,所有的 ...
- 题解报告:hdu 1686 Oulipo(裸KMP)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- 清除WebSphere部署应用所对应的JSP缓存
Web应用部署在WebSphere Application Server v8.5后程序一般放置在<AppServer>/profiles/<profile_name>/ins ...
- sql server 行转列 要注意的问题 pivot
select * from ( select mvqr.VoteQuestionId,mvqr.AnswerSolution from JY_MemberVoteQuestionRef as ...
- Redis远程连接
一.打开CMD命令 二.打开Redis客户端安装地址
- 卸载掉原有mysql
[root@xiaoluo ~]# rpm -qa | grep mysql // 这个命令就会查看该操作系统上是否已经安装了mysql数据库 有的话,我们就通过 rpm -e 命令 或者 rpm - ...
- Vue.js——router-link阻止click事件
router-link 只能单纯做路由跳转 https://segmentfault.com/q/1010000007896386