• 解题报告 问题1


    1. 题目 1.Problem1 首先,读入一个数n,n代表了下面的操作数,从第2至第n+1 行,每行有一个字符ch和一个数字q,若数字为i,代表将数字q加入数字序列中;若数字为f,代表让你找到数字序列中第q大的数字为多少(保证序列中至少为q个数字,即不会出现误解的情况)。

    输入样例:

    2

    i 1

    f 1

    输出样例

    1

    50%数据,n<=5000; 100%数据 n<=25 0000

    题目实质

    乍看,是一模拟。 事实上,模拟的都报 0 。 算法 Quicksort 过 5 个点。 Bst (二叉排序树),全点。 剩下的,就不用再说了吧。 注意事项 哥们,不要以为第一题就不会考你数据结构。

    代码 Bst + 模拟链表 (魂之挽歌)

    program test1;

    type tree=record

    x:longint;

    l,r,z,y:longint;

    end;

    var a:array[0..500000]of tree;

    i,j,n,k,tot:longint;

    c,ch:char;

    procedure insert(i,j:longint);

    begin

    if a[j].x<a[i].x then

    begin

    inc(a[i].z);

    if a[i].l=0 then a[i].l:=j else insert(a[i].l,j);

    end

    else

    begin

    inc(a[i].y);

    if a[i].r=0 then a[i].r:=j else insert(a[i].r,j);

    end;

    end;

    procedure find(i,x:longint);

    var t:longint;

    begin

    if x=a[i].y+1 then

    begin

    writeln(a[i].x);

    exit;

    end;

    if a[i].y>=x then find(a[i].r,x) else find(a[i].l,x-a[i].y-1);

    end;

    begin

    assign(input,'problem1.in');reset(input);

    assign(output,'problem1.out');rewrite(output);

    readln(n);

    readln(c,ch,k);

    a[1].x:=k;tot:=1;

    for i:=2 to n do

    begin

    readln(c,ch,k);

    if c='i' then

    begin

    inc(tot);

    a[tot].x:=k;

    insert(1,tot);

    end

    else

    find(1,k);

    end;

    close(input);close(output);

    end.

  • 相关阅读:
    SQL语句之DQL数据查询语言(select、desc)
    SQL语句之DML数据操作语言(insert、delete、update)
    SQL语句之DDL跟DCL
    MySQL的命令
    数据库配置文件
    Linux-用户/用户组身份提权
    MYSQL的连接管理与启动关闭流程
    MYSQL权限的管理
    MySQL5.6与MySQL5.7的区别
    MYSQL结构
  • 原文地址:https://www.cnblogs.com/SueMiller/p/2215394.html
Copyright © 2020-2023  润新知