| Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
|---|---|---|---|---|---|---|---|---|---|
| 109360 | 林泽豪 | 折半查找法 | C++ | Accepted | 100 | 1 MS | 296 KB | 524 | 2023-11-08 13:37:42 |
#include<bits/stdc++.h> using namespace std; int an[10000]; int l; bool mn=0;int a; void sb(int x,int y) { if(x==y&&l!=an[x]){ cout<<"-1"; exit(0); } if(l==an[(x+y)/2]||l==an[(x+y)/2+1]){ if(l==an[(x+y)/2]){ cout<<(x+y)/2; exit(0); }else{ cout<<(x+y)/2+1; exit(0); } }else{ if(an[(x+y)/2]>l){ sb((x+y)/2,1); }else{ sb((x+y)/2,a); } } } int main() { cin>>a; for(int i=1;i<=a;i++){ cin>>an[i]; } cin>>l; sb(1,a); return 0; }