Codeforces 536A Tavas and Karafs 二分+结论

本文探讨了一个等差数列序列,在限定条件下的优化问题。通过枚举和结论判断,找出使序列中所有数变为0的最长时间序列。

题目链接:点击打开链接

题意:有一个等差数列,从A开始,公差为B
然后n个询问。。。每个询问给定l,t,m
然后要求如果每次可以最多选择m个数,使这m个数-1,那么在t次操作中可以使l为左端点的最长序列中使所有数为0

思路:

枚举答案判可行就好了。

有一个结论,就是只要最大的数<=t,那么一定存在某种方案使得:当和 <= t*m 时能把所有数消光。



#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
template <class T>
inline bool rd(T &ret) {
    char c; int sgn;
    if (c = getchar(), c == EOF) return 0;
    while (c != '-' && (c<'0' || c>'9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
template <class T>
inline void pt(T x) {
    if (x <0) {
        putchar('-');
        x = -x;
    }
    if (x>9) pt(x / 10);
    putchar(x % 10 + '0');
}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int n;
ll A, B;
ll l, t, m, mx;
ll siz(ll x){
    return A + (x - 1)*B;
}
ll work(){
    if (siz(l) - t > 0)return -1;

    ll L = l, R = mx, ans = l;
    while (L <= R){
        ll mid = (L + R) >> 1;
        ll len = mid - l + 1;
        ll all = (siz(l) + siz(mid))*len / 2;
        ll M = min(m, len);
        if (all > t*M || siz(mid)>t)
            R = mid - 1;
        else {
            ans = mid;
            L = mid + 1;
        }
    }
    return ans;
}
int main() {
    while (cin >> A >> B >> n){
        mx = (1e6 - A) / B;
        mx++;
        while (n--){
            rd(l); rd(t); rd(m);
            pt(work()); puts("");
        }
    }
    return 0;
}


当前提供的引用内容并未提及关于Codeforces比赛M1的具体时间安排[^1]。然而,通常情况下,Codeforces的比赛时间会在其官方网站上提前公布,并提供基于不同时区的转换工具以便参赛者了解具体开赛时刻。 对于Codeforces上的赛事而言,如果一场名为M1的比赛被计划举行,则它的原始时间一般按照UTC(协调世界时)设定。为了得知该场比赛在UTC+8时区的确切开始时间,可以遵循以下逻辑: - 前往Codeforces官网并定位至对应比赛页面。 - 查看比赛所标注的标准UTC起始时间。 - 将此标准时间加上8小时来获取对应的北京时间(即UTC+8)。 由于目前缺乏具体的官方公告链接或者确切日期作为依据,无法直接给出Codeforces M1比赛于UTC+8下的实际发生时段。建议定期访问Codeforces平台查看最新动态更新以及确认最终版程表信息。 ```python from datetime import timedelta, datetime def convert_utc_to_bj(utc_time_str): utc_format = "%Y-%m-%dT%H:%M:%SZ" bj_offset = timedelta(hours=8) try: # 解析UTC时间为datetime对象 utc_datetime = datetime.strptime(utc_time_str, utc_format) # 转换为北京时区时间 beijing_time = utc_datetime + bj_offset return beijing_time.strftime("%Y-%m-%d %H:%M:%S") except ValueError as e: return f"错误:{e}" # 示例输入假设某场Codeforces比赛定于特定UTC时间 example_utc_start = "2024-12-05T17:35:00Z" converted_time = convert_utc_to_bj(example_utc_start) print(f"Codeforces比赛在北京时间下将是:{converted_time}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值