题解?
2026-07-14 11:06:19
发布于:广东
5阅读
0回复
0点赞
#include<bits/stdc++.h>
#define use using
#define space namespace
#define integer int
#define input cin
#define output cout
#define then ){
#define end }
#define endfunction return 0
#define nexti i++
#define with (
#define it )
#define to >>
#define the <<
#define endline ;
use space std endline
integer main with then
integer n endline
input to n endline
integer a[n]endline
for with integer i=0;i<n;nexti then input to a[i]endline end
integer l=0,r=n-1,mid endline
integer x;input to x endline
while with l<=r then
mid= with l+r it /2 endline
if with a[mid]==x then
output the mid+1 endline
endfunction endline
end
if with a[mid]>x then r=mid-1 endline end
if with a[mid]<x then l=mid+1 endline end
end output the -1 endline
end
全部评论 1
此处输入正文,2千字以内,可点击右上角【去预览】按钮查看markdown展示效果
7小时前 来自 广东
0







有帮助,赞一个