The auspicious solution of the Pascal fast standard process

Updated on Car 2024-02-09
6 answers
  1. Anonymous users2024-02-05

    How it works: Divide the array into two sides so that the numbers on the left are always smaller than those on the right, and then sort them separately (like divide and conquer).

    procdure sort(l,r:longint);

    vari,j,x,y:longint;

    begini:=l;j:=r;x:=a[(i+j) shr 1];

    shr 1 is div 2, and x seems to be just a }repeat for comparison

    while a[i]j) then beginy:=a[i];a[i]:=a[j];a[j]:=i;

    Swap the smaller number to the left}

    inc(i);dec(j);

    end;until i>j;

    repeat

    if lif i recursively continue to row}

    end;This app comes with Pascal and I write a few instructions based on my own understanding. It turns out that when I learned fast rowing, I didn't seem to be talking about this program.,But because I'm too familiar with this, I didn't remember that.。

  2. Anonymous users2024-02-04

    I haven't touched pascal for a few years, and even I, the teacher, have forgotten how to solve it.

  3. Anonymous users2024-02-03

    The quick order of the big bulls of the national training team is:

    procedure quicksort(l,r:longint);

    vari,j,x,yy:longint;

    begini:=l;j:=r;x:=a[(i+j) shr 1];

    repeat

    while a[i]x do dec(j);

    if i<=j then

    beginyy:=a[i];a[i]:=a[j];a[j]:=yy;

    inc(i);dec(j);

    end;until i>j;

    if iif lend;

    You can test with CENA, and this one is definitely the fastest. It may not make much of a difference when it comes to random data, but it's quick when it comes to some very bad data.

  4. Anonymous users2024-02-02

    Each data participating in the arrangement corresponds to a node of the binary tree, and if any node has a left (right) subtree, the data of each node of the left (right) subtree must be smaller (larger) than the data of that node. The sorting result is obtained by traversing the sorting binary tree in the middle order. The procedure is as follows:

    program pxtree;

    consta:array[1..8] of integer=(10,18,3,8,12,2,7,3);

    type point=^nod;

    nod=record

    w:integer;

    right,left:point ;

    end;var root,first:point;k:boolean;i:integer;

    procedure hyt(d:integer;var p:point);

    beginif p=nil then

    beginnew(p);

    with p^ do begin w:=d;right:=nil;left:=nil end;

    if k then begin root:=p; k:=false end;

    endelse with p^ do if d>=w then hyt(d,right) else hyt(d,left);

    end;procedure hyt1(p:point);

    beginwith p^ do

    beginif left<>nil then hyt1(left);

    write(w:4);

    if right<>nil then hyt1(right);

    endend;

    beginfirst:=nil;k:=true;

    for i:=1 to 8 do hyt(a[i],first);

    hyt1(root);writeln;

    end.

  5. Anonymous users2024-02-01

    constdx:array[1..4] of integer=(1,-1,0,0);

    dy:array[1..4] of integer=(0,0,1,-1);I don't need to talk about this, it's 4 directions.

    vara,f:array[1..100,1..100] of longint;

    r,c,i,j:integer;

    ans:longint;

    procedure work(x,y:integer);

    vari:integer;

    beginfor i:=1 to 4 do

    if (x+dx[i]>0) and (x+dx[i]<=r) and (y+dy[i]>0) and (y+dy[i]<=c) then begin

    if (a[x+dx[i],y+dy[i]]>a[x,y]) and (f[x+dx[i],y+dy[i]]=1) then this is more terrifying, mainly to determine whether it is out of bounds.

    work(x+dx[i],y+dy[i]);

    if (a[x+dx[i],y+dy[i]]>a[x,y]) and (f[x,y]ans then

    ans:=f[i,j];

    end;writeln(ans);

    end.This is made up by myself.,Then look at the annotation first.,If you run, delete the annotation.,It's the thing that will be crossed out.。

    By the way, attached in tyvj (that is the vijos of the alternative**,,If you are interested, you can go up and do the question,If you already know,Then when I it,Test results on it。

    vijosnt mini

    #01: accepted (0ms, 712kb)

    #02: accepted (0ms, 712kb)

    #03: accepted (0ms, 712kb)

    #04: accepted (0ms, 712kb)

    #05: accepted (0ms, 712kb)

    #06: accepted (0ms, 712kb)

    #07: accepted (0ms, 712kb)

    #08: accepted (0ms, 712kb)

    #09: accepted (43ms, 712kb)

    #10: accepted (43ms, 712kb)

    accepted / 100 / 87ms / 712kb

    It's a pleasure to answer.

  6. Anonymous users2024-01-31

    Idea: First sort the rank of n people from small to large, and then find the difference between the two adjacent numbers, and then sort the difference from small to large after staring at the answer, and finally output the sum of the first k differences.

    The procedure is as follows: Kai Xiao.

    program chess;

    var n,k,i,s:longint;a,b:packed array[1..100000] of longint;

    procedure kp(l,r:longint);

    var i,j,x,t:longint;

    begini:=l;j:=r;x:=a[(l+r) div 2];

    repeat

    while a[i]x do dec(j);

    if i<=j then begin t:=a[i];a[i]:=a[j];a[j]:=t;inc(i);dec(j);end;

    until i>j;

    if ix do dec(j);

    if i<=j then begin t:=b[i];b[i]:=b[j];b[j]:=t;inc(i);dec(j);end;

    until i>j;

    if iend;begin

    readln(n,k);for i:=1 to n do read(a[i]);kp(1,n);

    for i:=1 to n-1 do b[i]:=a[i+1]-a[i];kp2(1,n-1);

    for i:=1 to k do s:=s+b[i];writeln(s);

    end.

Related questions
4 answers2024-02-09

The Pascal compilation system is a system software. Pascal is the first structured programming language with rigorous syntax, clear hierarchy, easy to write and readable programs. Pascal language is widely used in various software, and the program is divided into name (self-proposed after program), setting (defined after var), start (begin), program (body), read (read read ln), and end (end), with strong structural hierarchy, rigorous and tight. >>>More

4 answers2024-02-09

I don't dare to be a noi master, but I have participated in noip. >>>More

6 answers2024-02-09

Refer to the upstairs, but upstairs doesn't know then without adding a statement? >>>More

6 answers2024-02-09

The human body is acidic and susceptible to various diseases. Like all chronic patients and cancer patients, the constitution is acidic, and the body of people who eat meat regularly is also more acidic, and if the acid in the body is not excreted in time, the rate of cancer is relatively high for a long time. When the acidity in the blood of the human body is too high, the synthesis and decomposition of purines causes foreign body inflammation in the tissues, which becomes the bane of gout. >>>More

5 answers2024-02-09

Since I was a child, I knew that the earth's resources are limited, as middle school students, we should cherish these priceless treasures more, energy conservation and emission reduction are closely related to the life of each of us, why many people go to Europe and say that it is like paradise? Why is Europe's ecology so good? Because people in Europe pay attention to the ecological environment! >>>More