3 条题解

  • 0
    @ 2024-7-29 10:02:07

    #include<bits/stdc++.h> using namespace std; int n; const int N=1e3+5; stack <int> s; int a[N]; int x=1,kk;

    signed main() { cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; } s.push(1); for(int i=1;i<=n;i++) { s.push(i); kk=n+1; while (kk--){ if(s.top()==a[x]){ s.pop(); x++; } } } if(s.size()==1){ cout<<"YES"; } else{ cout<<"NO"; } return 0; }

    • 0
      @ 2024-4-14 10:47:30

      #include <bits/stdc++.h> using namespace std; #define N 1005

      int main() { int n, a[N], st[N] = {}; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) { for (int j = a[i] + 1; j <= n; ++j) { if (st[j] == 1) { cout << "NO"; return 0; } } for (int j = 1; j < a[i]; ++j) { if (st[j] == 0) st[j] = 1; } st[a[i]] = 2; } cout << "YES"; return 0; }

      • 0
        @ 2024-4-14 10:47:19

        #include <bits/stdc++.h> using namespace std; #define N 1005

        int main() { int n, a[N], st[N] = {}; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) { for (int j = a[i] + 1; j <= n; ++j) { if (st[j] == 1) { cout << "NO"; return 0; } } for (int j = 1; j < a[i]; ++j) { if (st[j] == 0) st[j] = 1; } st[a[i]] = 2; } cout << "YES"; return 0; }

        • 1

        信息

        ID
        3047
        时间
        1000ms
        内存
        256MiB
        难度
        6
        标签
        递交数
        226
        已通过
        64
        上传者