• 2019牛客暑期多校训练营(第七场)A String(枚举)


    题目链接:https://ac.nowcoder.com/acm/contest/887#question

    题目大意:给一组”01“字符串,令其分割成极可能少的字符串,并且要满足每组字符串都是”完美的“。当一个字符串比它旋转后(即将字符串后面任意i位按顺序移到前面)的字符串都要小,则它是”完美的“。

    解题报告:字符串长度最长为200,直接模拟暴力枚举即可。

    AC代码:

     1 #include<bits/stdc++.h>
     2 #define numm ch-48
     3 #define pd putchar(' ')
     4 #define pn putchar('
    ')
     5 #define pb push_back
     6 #define fi first
     7 #define se second
     8 #define fre1 freopen("1.txt","r",stdin)
     9 #define fre2 freopen("3.txt","w",stdout)
    10 #define debug(args...) cout<<#args<<"->"<<args<<"
    ";
    11 using namespace std;
    12 template <typename T>
    13 void read(T &res) {
    14     bool flag=false;char ch;
    15     while(!isdigit(ch=getchar())) (ch=='-')&&(flag=true);
    16     for(res=numm;isdigit(ch=getchar());res=(res<<1)+(res<<3)+numm);
    17     flag&&(res=-res);
    18 }
    19 template <typename T>
    20 void write(T x) {
    21     if(x<0) putchar('-'),x=-x;
    22     if(x>9) write(x/10);
    23     putchar(x%10+'0');
    24 }
    25 typedef long long ll;
    26 typedef unsigned long long ull;
    27 const int maxn=1010;
    28 const int maxm=505;
    29 const int mod=1e9+7;
    30 const int inv2=500000004;
    31 const int N=32;
    32 vector<string>ans;
    33 bool check(string s) {
    34     string temp=s;
    35     for(int i=0;i<s.size();i++) {
    36         string tmp;
    37         tmp=temp[s.size()-1];
    38         tmp+=temp.substr(0,s.size()-1);
    39         if(tmp<s) return false;
    40         temp=tmp;
    41     }
    42     return true;
    43 }
    44 int main()
    45 {
    46     int _;
    47     read(_);
    48     while(_--) {
    49         ans.clear();
    50         string s;
    51         cin>>s;
    52         int i=0;
    53         while(i<s.size()) {
    54             int pos=i;
    55             for(int j=i;j<s.size();j++)
    56                 if(check(s.substr(i,j-i+1)))
    57                     pos=j;
    58             ans.pb(s.substr(i,pos-i+1));
    59             i=pos+1;
    60         }
    61         for(int i=0;i<ans.size();i++)
    62             if(i==0) cout<<ans[i];
    63             else cout<<' '<<ans[i];
    64         cout<<endl;
    65     }
    66     return 0;
    67 }
    代码在这里!
  • 相关阅读:
    Java 8 并行流与串行流
    Java 8 新增的 Stream
    Java 8 新增的 Lambda 表达式
    《CSS揭秘》 |用户体验与结构布局
    《CSS揭秘》 |阴影
    《CSS揭秘》 |形状
    《CSS揭秘》 |前言
    《CSS揭秘》 |背景与边框
    《CSS揭秘》 |CSS编码技巧
    《CSS揭秘》 |检测属性与属性值
  • 原文地址:https://www.cnblogs.com/wuliking/p/11372908.html
Copyright © 2020-2023  润新知