Sicily 1641 Binary Searchable

来源:互联网 发布:淘宝秒杀抢拍器怎么买 编辑:程序博客网 时间:2024/05/17 22:19

水题,如果一个数比左面的都大,比右面的都小就是Binary Researchable

// Problem#: 1641// Submission#: 3247168// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include<iostream>using namespace std;int main() {    int n;    while (cin >> n) {        int a[105];        for (int i = 0; i < n; i++) {            cin >> a[i];        }        int count = 0;        bool left, dext;        for (int i = 0; i < n; i++) {            left = dext = true;            for (int j = i + 1; j < n; j++) {                if (a[i] > a[j]) {                    dext = false;                    break;                }            }            for (int j = i - 1; j >= 0; j--) {                if (a[i] < a[j]) {                    left = false;                    break;                }            }            if (left && dext) {                count++;            }        }        cout << count << endl;    }}                                 


0 0
原创粉丝点击