[Construction] thinking cf1158B-The minimal unique substring

The meaning of problems

To n, k, let you construct a unique length n and a minimum substring of length k string 01.

The only substring mean, this substring can not find a second in this string. The 1010 is a single sub-string of 01010, 010 is a minimum substring unique, because it is a string of length 1, as there are a plurality of 0,1, 2, such as a string of length 01, 10, there are a plurality of , but you can not find two in the 010 series, the only child so minimal string 101 01010

answer

For convenience of description, we use a set of m m to represent 0, 1 means 1 alone, as 1m1m1 equivalent 100010001 (if m = 3) such as a string.

Consider 1m1m1m ...... 1m1m of such strings, provided that the string length is n (m + 1), the only difficult to find the minimum substring (n-2) (m + 1) +2

Consider 1m1m1m ...... 1m1m1 of such strings, provided that the string length is n (m + 1) +1, difficult to find a unique minimum substring (n-2) (m + 1) + 2 + 1

Consider 1m1m1m ...... 1m1m1000 such strings (assuming m> 3), provided that the length of the string of n (m + 1) + 1 + 3, difficult to find a unique minimum substring (n-2) (m + 1 ) + 1 + 2 + 3,

It found that the total length of all of the above cases large than a minimal string 2 * m, we consider this sequence to construct the nature

For example, 104

m=(10-4)/2=3;

10001000 10,0100 constructed unique minimum substring, ok!

But this does not ac all cases, the above configuration method is based on our total strings is larger than the minimum unique sub 2 * m on the basis of available rows.

Example 91

According to the above method to construct 100,001,000, does not match that Italy

10000100, we find him to meet the situation 1m1m100 form, but it is 4 m, a total length of 8, the only minimum substring 01, a length of 2

2 + 2 * m = 10> 8, this is not feasible,

We found that there must be two 1m job in a large string, such as 1,000,100,010 such a situation.

When two 1m does not exist? m = (nk) / 2;

n / (1 + m)> = 2 solve for k> = 2, we look Laid determination and k = 1 on the line

Code

#include <bits/stdc++.h>using namespace std;
int n,k,m;
int main()
{
    cin>>n>>k;
    m=(n-k)/2;
    if(k==1)
    {
        for(int i=1; i<n; i++)cout<<0;
        cout<<1;
    }
    else
    {
        for(int i=0; i<n; i++)
        {
            if(i%(m+1)==0)cout<<1;
            else cout<<0;
        }
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/wang_viscaria/article/details/92372190