标签:define code cond nbsp 字典序 %s cto 操作 using
题意:给定一个由a和b构成的字符串,可以选择翻转或不翻转他的每个前缀,翻转记为1不翻转记为0,求能将字符串排序的字典序最小的操作序列
n<=1e3
思路:考虑极长的一段a [t,w]
翻转t-1与w就能把这段a移到最前面
1 #include<cstdio> 2 #include<cstring> 3 #include<string> 4 #include<cmath> 5 #include<iostream> 6 #include<algorithm> 7 #include<map> 8 #include<queue> 9 #include<vector> 10 #include<ctime> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned int uint; 14 typedef unsigned long long ull; 15 typedef pair<int,int> PII; 16 typedef vector<int> VI; 17 #define fi first 18 #define se second 19 #define MP make_pair 20 #define N 210000 21 #define M 130 22 #define MOD 1000000007 23 #define eps 1e-8 24 #define pi acos(-1) 25 26 char a[N]; 27 int b[N],c[N]; 28 29 int main() 30 { 31 scanf("%s",a+1); 32 int n=strlen(a+1); 33 for(int i=1;i<=n;i++) 34 if(a[i]==‘a‘) c[i]=0; 35 else c[i]=1; 36 37 int i=0; 38 memset(b,0,sizeof(b)); 39 while(i<=n) 40 { 41 i++; 42 if(c[i]==1||i>n) continue; 43 int t=i; 44 int w=i; 45 while(i+1<=n&&c[i+1]==0){i++; w++;} 46 b[t-1]^=1; b[w]^=1; 47 } 48 for(int i=1;i<=n-1;i++) printf("%d ",b[i]); 49 printf("%d",b[n]); 50 return 0;
标签:define code cond nbsp 字典序 %s cto 操作 using
原文地址:https://www.cnblogs.com/myx12345/p/9872262.html