"BZOJ-3725" Matryca wtf

Source: Internet
Author: User
Tags uppercase letter

3725:pa2014 Final matryca time limit:5 Sec Memory limit:128 MB
submit:160 solved:96
[Submit] [Status] [Discuss] Description

There is a wall of length n to paint, you have a brush of length k. The walls and brushes are evenly divided into small units of length, and each of the brushes is stained with a certain color (solid color). You need to use this brush in every possible position on the wall (as long as the brush does not go beyond the wall and is aligned to the grid; there are n-k+1 locations). If one of the walls is painted with a different color, it will show a mixed color.

Now some squares on the wall need to be painted in a given color. Find the shortest brush length k to complete the task.

Input

The input is a string of length n (1<=n<=1000000), consisting of uppercase letters and asterisks. An uppercase letter indicates a solid color, and an asterisk indicates that the position color is not required.

Output

Outputs the smallest k.

Sample Inputa*b*b*aSample Output6HINT

Explain:

The color of the brush is Abbbba.

Source

Acknowledgement JCVB

Solution

Brain hole, nothing to say.

The answer is len-mindis+1.

Len is the length of the string, Mindis is the shortest distance of the adjacent non-different colors

Consider this:

If, so the color must be solid color, and 22 different, then obviously the brush is N, then if the different color adjacent to the nearest 2, then obviously brush brush for n-2+1

Similarly.....

Code
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#defineMAXN 1000010CharS[maxn],a;intL,n,a,dis;intMain () {scanf ("%s", s+1); N=strlen (s+1); A='&'; dis=N;  for(intI=1; i<=n; i++)        if(s[i]!='*')            {                if(a=='&') a=s[i],a=i; Else                    if(a!=S[i]) {Dis=min (dis,i-a); A=i,a=S[i]; }                    ElseA=i; } printf ("%d\n", n-dis+1); return 0;}

"BZOJ-3725" Matryca wtf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.