Codeforces Round 986 (Div. 2)

https://codeforces.com/contest/2028

A. Alice's Adventures in "Chess"

思路:因为数据范围很小,可以暴力遍历。

void solve()
{
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int x = 0, y = 0;
    for (int z = 0; z < 110; z++){
        for (int i = 0; i < n; i++){
            if (s[i] == 'N') y++;
            else if (s[i] == 'S') y--;
            else if (s[i] == 'E') x++;
            else if (s[i] == 'W') x--;
            if (x == a && y == b){
                cout << "YES" << endl;
                return ;
            }
        }
    }
    cout << "NO" << endl;
}

B. Alice's Adventures in Permuting

思路:注意分类讨论即可

void solve()
{
    int n, b, c;
    cin >> n >> b >> c;
    if (b == 0){
        if (c >= n){
            cout << n << endl;
        }
        else if (c >= n-2){
            cout << n-1 << endl;
        }
        else cout << -1 << endl;
    }
    else{
        if (c >= n){
            cout << n << endl;
        }
        else cout << n-max(0ll, 1+(n-c-1)/b) << endl;
    }
}

C. Alice's Adventures in Cutting Cake

思路:对于可以取中间的任意,而两边需要保证一定的条件的题,可以分成前缀和后缀来做,然后枚举要满足的两边。

void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n+1), pre(n+1);
    for (int i = 1; i<=n; i++){
        cin >> a[i];
        pre[i] = pre[i-1]+a[i];
    }
    vector<int> Prefix(m+1), Suffix(m+1);
    for (int i = 1, j = 1; i<=m; i++){
        while (j<=n && pre[j]-pre[Prefix[i-1]] < k){
            j++;
        }
        Prefix[i] = j;
    }
    Suffix[0] = n;
    for (int i = 1, j = n; i<=m; i++){
        while (j>=0 && pre[Suffix[i-1]]-pre[j] < k){
            j--;
        }
        Suffix[i] = j;
    }
    int ans = -1;
    for (int i = 0; i<=m; i++){
        if (Prefix[i] <= Suffix[m-i]){ // 相等表示Alice为空,其余正好满足
            ans = max(ans, pre[Suffix[m-i]]-pre[Prefix[i]]);
        }
    }
    cout << ans << endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wirepuller_king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值