UVa 10611

easy DC problem can be solved by binary search again...
/* UVas */
/*****************************************************************************/
int n, q, t;
vector<int> h;
int main(void) {
    while (cin>>n) {
        h.clear();
        for (int i=0; i<n; i++) {
            scanf("%d", &t);
            h.pb(t);
        }
        cin>>q;
        for (int i=0; i<q; i++) {
            scanf("%d", &t);
            vector<int>::iterator lo=lower_bound(all(h), t);
            vector<int>::iterator hi=upper_bound(all(h), t);
            int a=lo-h.begin()-1;
            int b=hi-h.begin();
            (a<n&&a>=0)?printf("%d", h[a]):printf("X");
            printf(" ");
            (b<n&&n>=0)?printf("%d", h[b]):printf("X");
            printf("\n");
        }
    }
    return 0;
}
/*****************************************************************************/

No comments :

Post a Comment