1051. Pop Sequence (25)解题报告

来源:互联网 发布:淘宝达人5篇帖子 编辑:程序博客网 时间:2024/06/05 19:58
#define _CRT_SECURE_NO_WARNINGS#include <cstdio>#include <cstdlib>#include <iostream>#include <stack>using namespace std;#define N 1100bool check(int a[], int n, int m);int main(void) {    int n, m, k;    setvbuf(stdout, new char[1 << 20], _IOFBF, 1 << 20);    scanf("%d %d %d", &m, &n, &k);    int i, j, a[N];    for (i = 0; i < k; i++) {        for (j = 0; j < n; j++) {            scanf("%d", a + j);        }        if (check(a, n, m)) {            puts("YES");        }        else {            puts("NO");        }    }    return 0;}bool check(int a[], int n, int m) {    stack<int> s;    int i, j;    for (i = 0, j = 0; i < n; i++) {        while (j < a[i]) {            s.push(++j);        }        if (s.size() > m) {            return false;        }        if (s.top() == a[i]) {            s.pop();        }        else {            return false;        }    }    return true;}
0 0