#include<bits/stdc++.h>
using namespace std;
int main(){
int ans=4;
int l=1,r=3,mid;
while(l<=r){
mid=(l+r)/2;
if(mid==ans){
cout<<"找到了";
break;
}else if(mid>ans){
r=mid-1;
cout<<"太大了"<<endl;
}else{
l=mid+1;
cout<<"太小了"<<endl;
}
}
return 0;
}二分查找代码模板,自取
文章信息与版本
文章信息
- 发布
- 2025年3月1日
- 收录
- 2025年12月12日
- 更新
- 2026年10月12日
- 篇幅
- 约 1 分钟
- 获赞
- 1