标签:namespace amp 二分 art c代码 ++ task medium cout
题目相关链接传送门:
1.https://blog.csdn.net/justidle/article/details/104593327?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-5&spm=1001.2101.3001.4242
2.https://vjudge.net/contest/378940#problem/C
我的AC代码:
#include<bits/stdc++.h> using namespace std; int lower_bound(int a[],int left,int right,int x) { while(left<=right) { int mid=(left+right)/2; if(a[mid]>=x) right=mid-1; else left=mid+1; } return left; } int main() { int n,m,i; cin>>n>>m; int a[n]; for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n); for(i=0;i<m;i++) { int x; cin>>x; if(x<a[0]) cout<<a[0]<<endl; else if(x>a[n-1]) cout<<"-1\n"; else { int pos=lower_bound(a,0,n-1,x); cout<<a[pos]<<endl; } } }
标签:namespace amp 二分 art c代码 ++ task medium cout
原文地址:https://www.cnblogs.com/dragondragon/p/13380201.html