[PA2014]Matryca
[PA2014]Matryca
题目大意:
有一堵长度为\(n(n\le10^6)\)的墙需要刷漆,你有一把长度为\(k\)的刷子。墙和刷子都被均匀划分成单位长度的小格,刷子的每一格中都沾有某种颜色的漆。你需要用这把刷子在墙上所有\(n-k+1\)个位置都刷一遍。如果墙上的某一格被不同颜色的漆刷过,那么它会呈现混合色。
现在墙上某些格子需要刷成给定的颜色,而另一些格子不不需要。求出能够完成任务的最短的刷子长度\(k\)。
思路:
求出每个格子向左扩展的最远的长度\(l_i\),答案就是\(\max\{n-l_i+1\}\)。
源代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=1e6+1;
char s[N];
int main() {
scanf("%s",s);
const int n=strlen(s);
int ans=1;
for(register int i=0,j=-1;i<n;i++) {
if(s[i]=='*') continue;
if(j!=-1&&s[i]!=s[j]) {
ans=std::max(ans,n-i+j+1);
}
j=i;
}
printf("%d\n",ans);
return 0;
}
[PA2014]Matryca的更多相关文章
- 【BZOJ-3725】Matryca 乱搞
3725: PA2014 Final Matryca Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 160 Solved: 96[Submit][St ...
- BZOJ 3721: PA2014 Final Bazarek
3721: PA2014 Final Bazarek Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 645 Solved: 261[Submit][ ...
- BZOJ 3709: [PA2014]Bohater
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 1050 Solved: ...
- bzoj3714: [PA2014]Kuglarz
[PA2014]KuglarzTime Limit: 20 Sec Memory Limit: 128 MBSubmit: 553 Solved: 317[Submit][Status][Discus ...
- 【贪心】bzoj 3709:[PA2014]Bohater
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 653 Solved: ...
- BZOJ3715: [PA2014]Lustra
3715: [PA2014]Lustra Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 237 Solved: 149[Submit][Status ...
- BZOJ3709: [PA2014]Bohater
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 339 Solved: ...
- BZOJ3713: [PA2014]Iloczyn
3713: [PA2014]Iloczyn Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 206 Solved: 112[Submit][Status ...
- BZOJ 3713: [PA2014]Iloczyn( 枚举 )
斐波那契数列<10^9的数很少很少...所以直接暴力枚举就行了... ------------------------------------------------------------- ...
随机推荐
- java的jdk
https://blog.fondme.cn/apidoc/jdk-1.8-baidu/
- go 数组 切片 字典 结构体
数组 ##数组的定义与赋值: 1. var num [3]int num = [3]int{1,2,3} 2. var num [3]int = [3]int {1,2,3} 3. num := [3 ...
- Fiddler--QuickExec
QuickExec在Fiddler中提供了比较快捷的功能服务. 在QuickExec输入框中输入命令,能快速地得到想要的结果. 快捷键:打开Fiddler后,按“Alt+q”,可将光标定位到Quick ...
- mysql 端口修改
mysql 修改端口 1. 停止mysql服务 2. 打开文件夹下my.ini文件.(E:\mysql-5.7-3307) 修改文件中的port值,注意两个地方: [client]default- ...
- A fine property of the non-empty countable dense-in-self set in the real line
A fine property of the non-empty countable dense-in-self set in the real line Zujin Zhang School o ...
- Groovy 设计模式 -- 适配器模式
Adapter Pattern http://groovy-lang.org/design-patterns.html#_adapter_pattern 适配器模式,对象存在一个接口, 此接口在此对象 ...
- ASP.NET Web API 之一 入门篇
一.基于RESTful标准的Web Api 原文讲解:https://www.cnblogs.com/lori/p/3555737.html 微软的web api是在vs2012上的mvc4项目绑定发 ...
- MS SQL Server 时间函数
日期和时间数据类型 数据类型 存储(字节) 日期范围 精确度 格式示例 DateTime 8 1753年1月1日 - 9999年12月31日 3 1/3毫秒 yyyy-MM-dd hh:mm:ss.n ...
- [JavaScript]ECMA-6 yield语法
概述 yield关键字用于并且仅限于生成器函数(generator)内部,作用是暂停(并返回)/重启(可选修改该栈环境变量)该函数栈环境. 一般语法 调用生成器函数时返回一个可迭代对象,当调用该对象的 ...
- Java_运算符
目录 一.算术运算符 二.关系运算符 三.位运算符 四.赋值运算符 五.条件运算符 六.instanceof 运算符 七.逻辑运算符 一.算术运算符 加 减 乘 除 取余 自增 自减(+ - * / ...