首页 > 其他 > 详细

Codeforces 1324C Frog Jumps

时间:2020-03-13 18:01:21      阅读:53      评论:0      收藏:0      [点我收藏+]

题目链接

最大最小, 很容易想到二分答案, 并且可以贪心验证, 复杂度为\(O(NlogN)\), 无视L, 每次选择最远的R作为新的起点进行贪心验证即可

#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii;

const int maxn = 2e5+5;

char str[maxn];
int n;

bool check(int d) {
    int l = 0;
    while(l < n) {
        for(int i = d; i >= 0; --i) {
            if(i == 0) return false;
            if(l+i >= n) return true;
            if(str[i+l] == 'R') {
                l += i;
                break;
            }
        }
    }
    return true;
}

void run_case() {
    cin >> (str+1);
    int l = 1, r = strlen(str+1) + 1, ans, mid;
    n = r;
    while(l <= r) {
        mid = (l+r) /2;
        if(check(mid)) {
            ans = mid;
            r = mid - 1;
        } else 
            l = mid + 1;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(2);
    int t; cin >> t;
    while(t--)
    run_case();
    cout.flush();
    return 0;
}

Codeforces 1324C Frog Jumps

原文:https://www.cnblogs.com/GRedComeT/p/12487554.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!