codeforces 390C Inna and Candy Boxes
这个题目看似不是很好下手,不过很容易发现每次询问的时候总是会问到第r个盒子是否有糖果;
这样的话就很好办事了;
维护两个数组;
一个sum数组:累加和;
一个in数组:如果i位是1的话,in[i]=in[i-k]+1;否则不加1,很好理解;
然后利用in数组可以找到本来应该有糖果的但是没有糖果的箱子的数目;
然后结合sum数组就可以的出结果;
#include<cstdio>
#include<cstring>
#define maxn 100005
using namespace std; char s[maxn];
int sum[maxn];
int in[maxn];
int n,w,k; int main()
{
scanf("%d%d%d",&n,&k,&w);
scanf("%s",s+);
for(int i=;i<=n;i++)
{
if(s[i]=='')
sum[i]+=sum[i-]+;
else sum[i]=sum[i-];
}
for(int i=;i<k;i++)
{
if(s[i]=='')
in[i]=;
}
for(int i=k;i<=n;i++)
{
if(s[i]=='')
in[i]=in[i-k]+;
else in[i]=in[i-k];
}
int l,r;
int need,noneed;
int tmp;
for(int i=;i<w;i++)
{
scanf("%d%d",&l,&r);
tmp=(r-l+)/k;
if(tmp==)tmp=;
need=(tmp-in[r]+in[l-]);
noneed=(sum[r]-sum[l-]-in[r]+in[l-]);
printf("%d\n",noneed+need);
}
return ;
}
codeforces 390C Inna and Candy Boxes的更多相关文章
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...
- cf C. Inna and Candy Boxes
题意:给你一个长度为n的只含有1和0的字符串,w个询问,每次询问输入l,r:在[l,r]中在l+k-1.l+2*k-1.......r的位置都必须为1,如果不为1的,变成1,记为一次操作,其它的地方的 ...
- cf B Inna and Candy Boxes
题意:输入n,然后输入n个数ai,再输入n个数bi,如果在1-ai中能找到两个数x,y,x和y可以相等,如果x+y=bi,答案加上x*y,否则减去1,让结果尽可能大,输出结果. #include &l ...
- Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)
B. Candy Boxes Problem's Link: http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...
- Codeforces 488B - Candy Boxes
B. Candy Boxes 题目链接:http://codeforces.com/problemset/problem/488/B time limit per test 1 second memo ...
- Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]
哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058 2014-11-22 06:52:58 njczy2010 B - Ca ...
- codeforces C. Inna and Huge Candy Matrix
http://codeforces.com/problemset/problem/400/C 题意:给你一个n*m的矩阵,然后在矩阵中有p个糖果,给你每个糖果的初始位置,然后经过x次顺时针反转,y次旋 ...
- codeforces C. Inna and Huge Candy Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/400/C 题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal ...
- codeforces 374A Inna and Pink Pony 解题报告
题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行 m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...
随机推荐
- pat 1006 Sign In and Sign Out (25)
At the beginning of every day, the first person who signs in the computer room will unlock the door, ...
- php gd 生成日历图
<?php //如果您提交了时间则显示您提交年月的日历,否则显示当前月份日历 if (isset($_GET['month']) && isset($_GET['year'])) ...
- Div+Css的初步运用
采用DIV+CSS模式的网站具有以下优势:1.表现和内容相分离 2.代码简洁,提高页面浏览速度 3.易于维护和改版 4.提高搜索引擎对网页的索引效率. 然后呢html文件中放置CSS有三种类型:内联. ...
- MySQL - 日志管理
在 MySQL 中,有 4 种不同的日志,分别是错误日志.二进制日志.查询日志和慢查询日志. 错误日志 错误日志记录了 MySQL 启动和停止时以及服务器在运行过程中发生严重错误时的相关信息. 查看错 ...
- android手机震动
Vibrator是安卓提供的震动器,其没有构造器,通过getSystemService(Context.VIBRATOR_SERVICE)方法获取对象.但使用此类时需要在清单文件中添加访问权限andr ...
- list,tuple,dict,字符串常用知识总结
创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...
- CS0016: 未能写入输出文件“c:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\data\34aae060\b7daa87d\App_Web_addadvice.aspx.cdcab7d2.ekhlcbjd.dll”--“目录名无效。 ”
产生原因: 应用程序运行时产生的临时文件需要存放到c:"windows"temp 文件夹下 而运行基于microsoft .net framework 框架下的应用程序 需要对te ...
- oracle 11G创建表空间、用户、配置监听和TNS
最近总在安装各种版本的oralce数据库做测试,11G,32位的,64位的,12C的,每次都折腾表空间,用户.tns啥的,这里记录下,再也不用现用现百度找了 一.创建表空间.用户 在plsql工具中 ...
- ASP.NET Web Service如何工作(2)
ASP.NET Web Service如何工作(2) [日期:2003-06-26] 来源:CSDN 作者:sunnyzhao(翻译) [字体:大 中 小] HTTP管道一旦调用了.asmx句柄,便 ...
- ###《Effective STL》--Chapter3
点击查看Evernote原文. #@author: gr #@date: 2014-09-13 #@email: forgerui@gmail.com Chapter3 关联容器 Topic 22: ...