跳到正文

题解

CF2040B Paint a Strip 题解

zrx0204约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年12月17日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 1 分钟
题目
CF2040B

版本

  1. v1当前

思路

我们已知尽量使用操作 2 给序列赋值。因为想使用操作 2 就必须左右两个端点为 11,且 x×2+2x \times 2 + 2 是能够满足要求的最远的距离,所以当序列前 xx 个数都已赋为 11 时,我们先对 ax×2+2a_{x \times 2 + 2} 使用操作 1,再以 axa_x 为左端点,ax×2+2a_{x \times 2 + 2} 为右端点使用操作 2 时,能够使操作 1 尽量少。

代码

C++
#include<bits/stdc++.h>
using namespace std;
int t;//多测
void solve(int t){
	while(t--){
        int n;
		scanf("%d", &n);
        int ans = 1;
        for(int x = 1; x < n; x *= 2, x += 2) ans++;//核心代码
        printf("%d\n", ans);//记得换行
    }
}
int main(){
    scanf("%d", &t);
    solve(t);
    return 0;
}
原文