大意略。
思路:推数据。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
int main()
{
int times = 0;
int n;
while(scanf("%d", &n) && n >= 0)
{
int t = 1, ans = 0;
while(t < n) { t *= 2; ans++; }
printf("Case %d: %d\n", ++times, ans);
}
return 0;
}
本文通过一个简单的程序演示了如何使用二进制查找法来确定一个整数在数列中的位置。该程序读取一个正整数并计算出它所在的二进制表示的位置,最后输出该位置。这一过程涉及到了基本的二进制运算和循环结构。
382

被折叠的 条评论
为什么被折叠?



