zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 86 (Rated for Div. 2)B Binary Period

    链接:https://codeforces.com/contest/1342/problem/B

    题意:给个01串的子串t让找原串s,要使得周期最小:

    满足条件:

    1,字符串s只包含0和1;

    2,s的长度不超过2⋅t (t是字符串t的长度);

    3,字符串t是字符串s的子序列;

    显然让s的周期最小只有两种情况,01间隔和全为相同的,

    两种情况考虑一下输出即可:

    code:

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll N=2e5+5;
    int a[N];
    int gcd(int a,int b)
    {
       return b==0?a:gcd(b,a%b);
    }
    void solve()
    {
       string s;
       cin>>s;
       int n=s.size();
       int flag=0;
       for(int i=0; i<n-1; i++)
       {
          if(s[i]!=s[i+1])
           flag=1;
       }
       if(!flag)
        cout<<s<<endl;
       else
       {
          for(int i=0; i<n; i++)
          {
             cout<<s[i];
             if(s[i]==s[i+1])
              {
                 if(s[i]=='1')
                  cout<<0;
                else
                 cout<<1;
              }
          }
          cout<<endl;
       }
    }
    int main()
    {
       int t;
       scanf("%d",&t);
       while(t--) solve();
       //system("pause");
        return 0;
    }
  • 相关阅读:
    centos
    ssh 登录 centos 服务器
    Sql NoSql
    Java
    PHP
    React Hooks使用
    前端优化tips
    Error:Node Sass version 5.0.0 is incompatible with ^4.x 解决
    css换行
    git 关联多个远程仓库
  • 原文地址:https://www.cnblogs.com/sweetlittlebaby/p/12788995.html
Copyright © 2011-2022 走看看