思路
我们已知尽量使用操作 2 给序列赋值。因为想使用操作 2 就必须左右两个端点为 ,且 是能够满足要求的最远的距离,所以当序列前 个数都已赋为 时,我们先对 使用操作 1,再以 为左端点, 为右端点使用操作 2 时,能够使操作 1 尽量少。
代码
#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;
}