全WA了……万分感谢

P2249 【深基13.例1】查找

sunming @ 2023-07-25 10:29:39

本人蒟蒻,大佬们轻点喷

#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long

using namespace std;

int main(){
    int n,m,z=1;
    cin >>n>>m;
    LL a[n+1];
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int b[m+1];
    for (int i = 1; i <= m; i++){
        cin >> b[i];
    }
    int r,l=n-1,c;
    for(int i = 0; i <= m; i++){
        c = (l+r) / 2;
        if (c == b[z]) {
            cout << c << " ";
            z++; r=1; l=n-1;
            if(z > m){
                break;
            }
        }
        if (c > b[z]) r = c;
        if (c < b[z]) l = c+1;
        if (l > r) cout << -1 << " "; z++;
    }
    return 0;
}

by zhangyuanxiao @ 2023-07-25 10:31:52

@sunming 你这二分……


|