More than 2019 cattle off summer school camp (seventh) A String (enumeration)

Topic links: https://ac.nowcoder.com/acm/contest/887#question

Title effect: to a group of "01" string, so that it may be divided into very small string, each string is satisfied and to "perfect." When a string of rotation than it is (to be any string of i bits in order to move back the front) of the string to be small, then it is "perfect."

Report problem solving: string length of up to 200 direct enumeration can be simulated violence.

AC Code:

 1 #include<bits/stdc++.h>
 2 #define numm ch-48
 3 #define pd putchar(' ')
 4 #define pn putchar('\n')
 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<<"\n";
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 }
Code here!

 

Guess you like

Origin www.cnblogs.com/wuliking/p/11372908.html