about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--others/volume1/036.pas57
-rw-r--r--others/volume1/040.pas27
-rw-r--r--others/volume1/044.pas34
-rw-r--r--others/volume1/045.pas31
-rw-r--r--others/volume1/046.pas16
-rw-r--r--others/volume1/cmath.pas22
-rw-r--r--others/volume1/sortnfind.pas12
7 files changed, 192 insertions, 7 deletions
diff --git a/others/volume1/036.pas b/others/volume1/036.pas
new file mode 100644
index 0000000..a958e93
--- /dev/null
+++ b/others/volume1/036.pas
@@ -0,0 +1,57 @@
+var
+  n, i: int16;
+  a: array of int64;
+  idx: array of int16;
+
+
+procedure sort(l, r: int16);
+  var
+    i, j: int16;
+    x, y: int64;
+
+  begin
+    i := l;
+    j := r;
+    x := a[(l + r) div 2];
+
+    repeat
+      while a[i] < x do
+        inc(i);
+
+      while x < a[j] do
+        dec(j);
+
+      if i <= j then
+        begin
+          y := a[i];
+          a[i] := a[j];
+          a[j] := y;
+          y := idx[i];
+          idx[i] := idx[j];
+          idx[j] := y;
+          inc(i);
+          dec(j)
+        end
+    until i > j;
+
+    if l < j then
+      sort(l, j);
+    if i < r then
+      sort(i, r)
+  end;
+
+
+begin
+  readln(n);
+  setlength(a, n);
+  setlength(idx, n);
+  for i := 0 to n - 1 do
+    begin
+      read(a[i]);
+      idx[i] := i + 1
+    end;
+  sort(0, n - 1);
+  for i in idx do
+    write(i, ' ');
+  writeln
+end.
diff --git a/others/volume1/040.pas b/others/volume1/040.pas
new file mode 100644
index 0000000..919304c
--- /dev/null
+++ b/others/volume1/040.pas
@@ -0,0 +1,27 @@
+var
+  n, i, c: int16;
+  x, a, b: int32;
+  s: array of boolean;
+
+begin
+  c := 0;
+  readln(n, x);
+  setlength(s, n);
+  for i := 0 to n - 1 do
+    s[i] := false;
+  for i := 0 to n - 1 do
+    begin
+      readln(a, b);
+      if (a <= x) and
+         (x <= b) then
+        begin
+          inc(c);
+          s[i] := true
+        end
+    end;
+  writeln(c);
+  for i := 0 to n - 1 do
+    if s[i] then
+      write(i + 1, ' ');
+  writeln
+end.
diff --git a/others/volume1/044.pas b/others/volume1/044.pas
new file mode 100644
index 0000000..1ac29fe
--- /dev/null
+++ b/others/volume1/044.pas
@@ -0,0 +1,34 @@
+var
+  n, n0, m, m0, i: int16;
+  a: array of int16;
+  b: array of boolean;
+
+begin
+  readln(n, m);
+  n0 := n;
+  setlength(a, n);
+  setlength(b, n);
+  for i := 0 to n - 1 do
+    b[i] := true;
+  i := -1;
+  while n0 > 0 do
+    begin
+      m0 := m;
+      while m0 > 0 do
+        begin
+          repeat
+            if i < n - 1 then
+              inc(i)
+            else
+              i := 0
+          until b[i];
+          dec(m0)
+        end;
+      b[i] := false;
+      a[n - n0] := i + 1;
+      dec(n0)
+    end;
+  for i in a do
+    write(i, ' ');
+  writeln
+end.
diff --git a/others/volume1/045.pas b/others/volume1/045.pas
new file mode 100644
index 0000000..eca1c9d
--- /dev/null
+++ b/others/volume1/045.pas
@@ -0,0 +1,31 @@
+uses cmath;
+
+var
+  n: int8 = 0;
+  i, j, c: int8;
+  p: array[1..20] of uint8;
+  b: array of boolean;
+  idx: uint64 = 1;
+
+begin
+  while not eof(input) do
+    begin
+      inc(n);
+      read(p[n])
+    end;
+  setlength(b, n + 1);
+  for i := 1 to n do
+    b[i] := true;
+  for i := 1 to n do
+    begin
+      c := 0;
+      for j := 1 to n do
+        if j = p[i] then
+          break
+        else if b[j] then
+          inc(c);
+      idx := idx + c * factorial[n - i];
+      b[p[i]] := false
+    end;
+  writeln(idx)
+end.
diff --git a/others/volume1/046.pas b/others/volume1/046.pas
new file mode 100644
index 0000000..146ba7a
--- /dev/null
+++ b/others/volume1/046.pas
@@ -0,0 +1,16 @@
+var
+  n, i, j: int16;
+
+begin
+  readln(n);
+  for i := 0 to n - 1 do
+    begin
+      if i mod 2 = 0 then
+        for j := 1 to n do
+          write(i * n + j, ' ')
+      else
+        for j := n downto 1 do
+          write(i * n + j, ' ');
+      writeln
+    end
+end.
diff --git a/others/volume1/cmath.pas b/others/volume1/cmath.pas
index 9f4f1f5..67b22a5 100644
--- a/others/volume1/cmath.pas
+++ b/others/volume1/cmath.pas
@@ -4,6 +4,28 @@ unit cmath;
 interface
 
   const
+    factorial: array[1..20] of uint64 = (
+      1,
+      2,
+      6,
+      24,
+      120,
+      720,
+      5040,
+      40320,
+      362880,
+      3628800,
+      39916800,
+      479001600,
+      6227020800,
+      87178291200,
+      1307674368000,
+      20922789888000,
+      355687428096000,
+      6402373705728000,
+      121645100408832000,
+      2432902008176640000
+    );
     fibonacci: array[1..93] of uint64 = (
       1,
       1,
diff --git a/others/volume1/sortnfind.pas b/others/volume1/sortnfind.pas
index a65cde0..24f48f6 100644
--- a/others/volume1/sortnfind.pas
+++ b/others/volume1/sortnfind.pas
@@ -15,9 +15,9 @@ interface
 implementation
 
   procedure qsort(var a : intar);
-    procedure sort(l, r: integer);
+    procedure sort(l, r: int64);
       var
-        i, j, x, y: integer;
+        i, j, x, y: int64;
 
       begin
         i := l;
@@ -26,24 +26,22 @@ implementation
 
         repeat
           while a[i] < x do
-            inc(i);
-
+            i := i + 1;
           while x < a[j] do
-            dec(j);
+            j := j - 1;
 
           if i <= j then
             begin
               y := a[i];
               a[i] := a[j];
               a[j] := y;
-              inc(i);
+              i := i + 1;
               j := j - 1
             end
         until i > j;
 
         if l < j then
           sort(l, j);
-
         if i < r then
           sort(i, r)
       end;