点击这里更换您喜欢的皮肤wtboj 首页
请点击这里登入noios   首页 入门 c++讲义 入门教程视频 其他页面 入门视频 站务 公告 | 题库 记录 竞测 测试 闯关 作业 排名 团队 讨论 | 换肤 | 登入 注册  
News >>   新增功能:各团队管理员可以发布本团队作业了 ()

讨论 Discussion
 
3.10
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,k,i,j,a[10000]={0};
cin>>n>>k;
for(i=1;i<=n;i++)cin>>a[i];
int s=1;
int t=n;
while(s<=t){//计算中间位置
if(a[t]==k){
cout<<t;//找到目标返回下标
break;
t=(t+e)/2;
}
else if (k>a[t] )
s=t+1;//目标在右半部分
else
t=t-1;//目标在左半部分
}
if(s>t){cout<<-1;}
return 0;
}
( )

此主题无回复显示
发布讨论主题 回复讨论主题
 Copyright wtboj © 2005-2006. www.wutuobang.date Powered by wtboj 关于 联系 帮助
 wtboj Information ---- Total Users : 1368 | Online Users / Processes : 0 / 26 | Processed Time : 31 ms | Server Time : 2026/3/14 12:26:59