zoukankan      html  css  js  c++  java
  • [PA2014]Matryca

    [PA2014]Matryca

    题目大意:

    有一堵长度为(n(nle10^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
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    CMS、G1收集器
    一文入门Redis
    一文解析TCP/UDP
    ubuntu官方源
    一、单体架构分析
    netty简介2
    netty简介
    安装vmware tool
    jdk1.8安装(转载)
    HTTP1.0、HTTP1.1 和 HTTP2.0 的区别
  • 原文地址:https://www.cnblogs.com/skylee03/p/10207253.html
Copyright © 2011-2022 走看看