net core 5.0 docker 映象訪問sql server 出現SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.問題解決方案
阿新 • • 發佈:2020-12-04
Description
Sample Output
二分查詢又叫折半查詢。它採用的是"分治策略"。
給出從小到大排好序的M個整數,查詢是否存在某個整數,如果存在,則輸出其位置。
Input第一行是一個整數 M ( 0 < M ≤ 200000 ) 表示整數的個數。
接下來是M個整數,每個整數之間用一個空格分隔。
接下來一行是一個整數N,表示要查詢的關鍵字個數。
接下來N個整數,表示要查詢的關鍵字key。每個key之間一個空格分隔。
Output對每個要查詢的key,輸出一行結果。
如果找到,輸出key在這M個整數的位置,位置從0開始編號。
如果找不到,則輸出 Not Found
Sample Input10
1 2 4 6 7 8 9 11 20 85
4
1 5 20 99
0
Not Found
8
Not Found
#include<bits/stdc++.h> const int maxn = 2e5+10; using namespace std; int a[maxn]; int main() { int n; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; int m;cin>>m; while(m--){ int x;cin>>x; int l=0,r=n-1,index; while(l<=r){ index=(l+r)/2; if(a[index]==x) break; if(a[index]<x) l=index+1; else r=index-1; } if(l<=r)printf("%d\n",index); else printf("Not Found\n"); } }