Codeforces Round #519 by Botan Investments C. Smallest Word

On a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of the chessboard, you can assign the coordinates (r,c), where r is the number of the row, and c is the number of the column.

The white king has been sitting in a cell with (1,1) coordinates for a thousand years, while the black king has been sitting in a cell with (n,n) coordinates. They would have sat like that further, but suddenly a beautiful coin fell on the cell with coordinates (x,y)…

Each of the monarchs wanted to get it, so they decided to arrange a race according to slightly changed chess rules:

As in chess, the white king makes the first move, the black king makes the second one, the white king makes the third one, and so on. However, in this problem, kings can stand in adjacent cells or even in the same cell at the same time.

The player who reaches the coin first will win, that is to say, the player who reaches the cell with the coordinates (x,y) first will win.

Let’s recall that the king is such a chess piece that can move one cell in all directions, that is, if the king is in the (a,b) cell, then in one move he can move from (a,b) to the cells (a+1,b), (a−1,b), (a,b+1), (a,b−1), (a+1,b−1), (a+1,b+1), (a−1,b−1), or (a−1,b+1). Going outside of the field is prohibited.

Determine the color of the king, who will reach the cell with the coordinates (x,y) first, if the white king moves first.


对每个前缀从小到大选择反转或者不反转,问最后能得到的字典序最小的字符串的操作序列。
很有意思得一道题,我们发现类似于abab的串我们可以翻转两次让他变成aabb,稍加讨论,我们可以发现所有的a都可以借由翻转来到最前面。
设下的只要构造这个序列就行了

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pb push_back
using namespace std;
int ans[2001];
int main()
{
    string s;
    cin>>s;
    int n = s.length();
    int sta = (s[0] == 'a');
    for(int i = 1;i<n;i++)
    {
        if(sta)
        {
            if(i != n-1 && s[i] == 'b' && s[i+1] == 'a')
            {
                ans[i] = 1;
                sta ^=1;
            }
        }
        else
        {
            if(i == n-1 || (s[i] == 'a' && s[i+1] == 'b'))
            {
                sta ^= 1;
                ans[i] = 1;
            }
        }
    }
    for(int i = 0;i<n;i++)
    {
        cout<<ans[i]<<' ';

    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值