《笔记2》
2025-04-05 09:39:22
发布于:广东
物理,功能,电气,时间
freopen("aaa.in","r",stdin);//输入
freopen("aaa.in","w",stdout);//输出
fclose(stdin);//关闭输入
fclose(stdout);//关闭输出
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main(){
int n,m=0,x;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
cin>>x;
int l=1,r=n;
while(l<r){
int m=(l+r)/2;
if(a[m]>=x) r=m;
else l=m+1;
}
if(a[l]==x) cout<<l;
else cout<<-1;
return 0;
}
//【栈】
#include<stack>
stack<int> stk;
stk.push(666);//可填别的 入栈
stk.pop(); // 出栈
stk.top(); // 栈项
stk.size(); // 长度
stk.empty(); // 为空(?)
//【队列】
#include<queue>
queue<int> stk;
que.push(666);//可填别的 入队
que.pop(); // 出队
que.top(); // 队头
que.size(); // 队列
que.empty(); // 为空(?)
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main(){
int n,m=0,x;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
cin>>x;
int l=1,r=n;
while(l<r){
int m=(l+r+1)/2;
if(a[m]<=x) l=m;
else r=m-1;
}
cout<<l;
return 0;
}
这里空空如也
有帮助,赞一个