首页 / 客观题库

70287 - CSP-S第一轮同测模拟卷1-完善程序1

题目(材料题)

(1)单调栈与笛卡尔树给定一个长度为 n 的数组 a,构建其笛卡尔树(Cartesian Tree)。

01 #include <iostream>

02 #include <stack>

03 using namespace std;

04

05 const int MAXN = 100005;

06 int n;

07 int a[MAXN];

08 int lc[MAXN], rc[MAXN];  // 左右孩子

09 int parent[MAXN];

10 int root;

11

12 void build() {

13     stack<int> st;

14     for (int i = 1; i <= n; ++i) {

15         int last = 0;

16         while (!st.empty() && ①) {

17             last = st.top();

18             st.pop();

19         }

20         if (!st.empty()) {

21             ②;

22             rc[st.top()] = i;

23         }

24         if (last != 0) {

25             ③;

26         }

27         ④;

28     }

29     ⑤;

30 }

31

32 int main() {

33     cin >> n;

34     for (int i = 1; i <= n; ++i) cin >> a[i];

35     build();

36     cout << root << endl;

37     return 0;

38 }

||
( 单选 )

33. ①处应填(    )

A a[st.top()] >= a[i]

B a[st.top()] < a[i]

C a[st.top()] > a[i]

D st.top() > i

( 单选 )

34. ②处应填(    )

A parent[i] = st.top()

B parent[st.top()] = i

C lc[i] = st.top()

D rc[i] = st.top()

( 单选 )

35. ③处应填(   )

A rc[i] = last

B lc[i] = last

C parent[last] = i

D parent[i] = last

( 单选 )

36. ④处应填(    )

A st.push(parent[i])

B st.push(last)

C st.top() = i

D st.push(i)

( 单选 )

37. ⑤处应填(     )

A root = st.top()

B while (!st.empty()) st.pop()

C root = 1

D root = parent[st.top()]

意见反馈

    最多上传3张图片,格式为JPG、PNG、JPEG,单张不超过5MB

    注册

    发送验证码

    密码必须包含数字、字母和特殊字符

    找回密码

    发送验证码

    密码必须包含数字、字母和特殊字符

    运行 ID:67149

    • 测试点1:Accepted
    • 用时:0 ms
    • 内存:288 kb
    • 测试点2:Accepted
    • 用时:0 ms
    • 内存:288 kb
    输入
    203
    输出
    203

    test

    测评信息

    错误.in文件下载

    错误.out文件下载

    运行 ID:67149

    2019-01-24 15:06:36