zoukankan      html  css  js  c++  java
  • cf1043C. Smallest Word(贪心)

    题意

    题目链接

    Sol

    这题打cf的时候真的是脑残,自己造了个abcdad的数据开心的玩了半天一脸懵逼。。。最后还好ycr大佬给了个思路不然就凉透了。。。

    首先不难看出我们最后一定可以把字符串弄成(aaaabbb)的形式,若当前位和下一位不一样就直接转就行了

    注意特判一下最后一个位置

    /*
    
    */
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    #include<vector>
    #include<set>
    #include<queue>
    #include<cmath>
    #include<tr1/unordered_map> 
    //#include<ext/pb_ds/assoc_container.hpp>
    //#include<ext/pb_ds/hash_policy.hpp>
    #define Pair pair<int, int>
    #define MP(x, y) make_pair(x, y)
    #define fi first
    #define se second
    //#define int long long
    #define LL long long
    #define ull unsigned long long
    #define rg register
    #define pt(x) printf("%d ", x);
    //#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 22)], *p1 = buf, *p2 = buf;
    //char obuf[1<<24], *O = obuf;
    //void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
    //#define OS  *O++ = ' ';
    using namespace std;
    //using namespace __gnu_pbds;
    const int MAXN = 1e5 + 10, INF = 1e9 + 10, mod = 998244353;
    const double eps = 1e-9;
    inline int read() {
    	char c = getchar();
    	int x = 0, f = 1;
    	while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
    	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    	return x * f;
    }
    int N, flag[MAXN];
    string s, r;
    string RE(string s, int pre) {
    	for(int i = 0; i < pre; i++) swap(s[i], s[pre - i]);
    	return s;
    }
    main() {
    	cin >> s;
    	int N = s.length();
    	for(int i = 0; i < N; i++) {
    		if(s[i] != s[i + 1])
    			s = RE(s, i), flag[i] = 1;
    //		cout << s << endl;
    	}
    	string a = s, b = RE(s, N - 1);
    	//cout << a << " " << b << endl;
    	if(flag[N - 1] && (b < a)) flag[N - 1] = 0;
    	for(int i = 0; i < N; i++) printf("%d ", flag[i]);
    	return 0;
    }
    
  • 相关阅读:
    web api 初体验之 GET和POST传参
    清除系统日志及数据库(sql server)日志最佳实践
    大家好啊!
    [oc学习笔记]多态
    [oc学习笔记]便利构造器无法被继承
    [oc学习笔记]字符串
    antd异步加载的树
    react新建页面步骤(新手必看)
    ECharts 经常会修改到的一些样式配置
    关于数组的一些常用方法
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9871690.html
Copyright © 2011-2022 走看看