• 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;
    }
    
  • 相关阅读:
    另一种逆元的求解方法
    SSHFS使用笔记
    HDU 2612 Find a way (BFS)
    POJ 3984 迷宫问题 (BFS + Stack)
    计蒜客 疑似病毒 (AC自动机 + 可达矩阵)
    HUD 1426 Sudoku Killer (DFS)
    计蒜客 成绩统计 (Hash表)
    计蒜客 劫富济贫 (Trie树)
    POJ 2251 Dungeon Master (BFS)
    [IB]Integration Broker 是如何处理传入的请求(Part 2)
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9871690.html
Copyright © 2020-2023  润新知