about summary refs log tree commit diff
path: root/others
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-19 11:37:07 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-19 11:37:07 +0700
commita53c4128c29f98b5fdfd9b0e13a3bbe094d975ec (patch)
tree77351187cc721bb535ffb3ff140e1355276ba8c2 /others
parentfed71ad5b9c7e3524931b939ec369a559cf2b0b9 (diff)
downloadcp-a53c4128c29f98b5fdfd9b0e13a3bbe094d975ec.tar.gz
Update others/volume1
Diffstat (limited to 'others')
-rw-r--r--others/volume1/069.pas40
-rw-r--r--others/volume1/071.pas42
-rw-r--r--others/volume1/072.pas24
-rw-r--r--others/volume1/074.pas30
-rw-r--r--others/volume1/075.pas30
-rw-r--r--others/volume1/clib.pas26
6 files changed, 178 insertions, 14 deletions
diff --git a/others/volume1/069.pas b/others/volume1/069.pas
new file mode 100644
index 0000000..2e92fd8
--- /dev/null
+++ b/others/volume1/069.pas
@@ -0,0 +1,40 @@
+uses clib;
+
+var
+  n, i, j: int16;
+  b, c: array of int64;
+  tmp: uint64 = 18446744073709551615;
+
+function absum(x, y: int64): uint64;
+  begin
+    if (x < 0) and
+       (y < 0) then
+      exit(-x - y)
+    else if (x > 0) and
+            (y > 0) then
+      exit(x + y);
+    absum := abs(x + y)
+  end;
+
+begin
+  readln(n);
+  setlength(b, n);
+  for i := n - 1 downto 0 do
+    read(b[i]);
+  qsort(b);
+  setlength(c, n);
+  for j := 0 to n - 1 do
+    read(c[j]);
+  qsort(c);
+  while (i < n) and
+        (j >= 0) do
+    begin
+      if absum(b[i], c[j]) < tmp then
+        tmp := absum(b[i], c[j]);
+      if b[i] + c[j] < 0 then
+        i := i + 1
+      else
+        j := j - 1
+    end;
+  writeln(tmp)
+end.
diff --git a/others/volume1/071.pas b/others/volume1/071.pas
new file mode 100644
index 0000000..59191da
--- /dev/null
+++ b/others/volume1/071.pas
@@ -0,0 +1,42 @@
+{$mode objfpc}
+uses math, clib;
+
+var
+  n, m, i, j: int16;
+  (* For math compatibility *)
+  a: array of array of integer;
+  res: array of integer;
+  (* For clib compatibility *)
+  rowmin: array of int64;
+  colmax: int64;
+
+begin
+  readln(n, m);
+  setlength(a, n);
+  setlength(rowmin, n);
+  for i := 0 to n - 1 do
+    begin
+      setlength(a[i], m);
+      for j := 0 to m - 1 do
+        read(a[i][j]);
+      rowmin[i] := minvalue(a[i])
+    end;
+  qsort(rowmin);
+  setlength(res, 0);
+  for j := 0 to m - 1 do
+    begin
+      colmax := a[0][j];
+      for i := 1 to n - 1 do
+        if a[i][j] > colmax then
+          colmax := a[i][j];
+      if bsearch(rowmin, colmax) > -1 then
+        begin
+          setlength(res, length(res) + 1);
+          res[length(res) - 1] := colmax
+        end
+    end;
+  writeln(length(res));
+  for i in res do
+    write(i, ' ');
+  writeln
+end.
diff --git a/others/volume1/072.pas b/others/volume1/072.pas
new file mode 100644
index 0000000..40c7ca5
--- /dev/null
+++ b/others/volume1/072.pas
@@ -0,0 +1,24 @@
+var
+  n, c, i, j, idx, max, tmp: int16;
+
+begin
+  readln(n);
+  max := 0;
+  for i := 1 to n do
+    begin
+      tmp := 0;
+      for j := 1 to n do
+        begin
+          read(c);
+          if c = 1 then
+            inc(tmp)
+        end;
+      if tmp > max then
+        begin
+          max := tmp;
+          idx := i
+        end
+    end;
+  writeln(idx, ' ', max)
+end.
+
diff --git a/others/volume1/074.pas b/others/volume1/074.pas
new file mode 100644
index 0000000..6006157
--- /dev/null
+++ b/others/volume1/074.pas
@@ -0,0 +1,30 @@
+var
+  n, i, j, max: int16;
+  a: array of int64;
+
+function zigzag(i, j: int16): boolean;
+  begin
+    if j - i < 2 then
+      exit(true);
+    if (a[j - 1] - a[j - 2]) * (a[j - 1] - a[j]) > 0 then
+      exit(true);
+    zigzag := false
+  end;
+
+begin
+  readln(n);
+  setlength(a, n);
+  for i := n - 1 downto 0 do
+    read(a[i]);
+  max := 0;
+  while i < n - 1 do
+    for j := i + 1 to n - 1 do
+      if (j = n - 1) or
+         not zigzag(i, j + 1) then
+        begin
+          if j - i > max then
+            max := j - i;
+          i := j
+        end;
+  writeln(max + 1)
+end.
diff --git a/others/volume1/075.pas b/others/volume1/075.pas
new file mode 100644
index 0000000..1ccacaf
--- /dev/null
+++ b/others/volume1/075.pas
@@ -0,0 +1,30 @@
+uses clib;
+
+var
+  n, idx, i, j: int16;
+  a, b: array of int64;
+  k: int64;
+
+begin
+  readln(n, k);
+  setlength(a, n);
+  setlength(b, n);
+  for i := 0 to n - 1 do
+    begin
+      read(a[i]);
+      b[i] := a[i]
+    end;
+  qsort(b);
+  for i := 0 to n - 1 do
+    begin
+      idx := bsearch(b, a[i] + k);
+      if idx > -1 then
+        for j := 0 to n - 1 do
+          if a[j] = b[idx] then
+            begin
+              writeln('YES'#10, i + 1, ' ', j + 1);
+              exit
+            end
+    end;
+  writeln('NO')
+end.
diff --git a/others/volume1/clib.pas b/others/volume1/clib.pas
index 28dffb2..101bad3 100644
--- a/others/volume1/clib.pas
+++ b/others/volume1/clib.pas
@@ -131,10 +131,10 @@ interface
   function issquare(x: int64): boolean;
   function ispalindrome(s: ansistring): boolean;
   function all(b: array of boolean): boolean;
-  function binin(
+  function bsearch(
     a: intar;
     x: int64
-  ): boolean;
+  ): int64;
 
 
 implementation
@@ -230,30 +230,28 @@ implementation
     end;
 
 
-  function binin(
+  function bsearch(
     a: intar;
     x: int64
-  ): boolean;
+  ): int64;
 
     var
-      l, h, mid: uint64;
+      l, h, m: int64;
 
     begin
       l := 0;
       h := length(a) - 1;
-
       while l <= h do
         begin
-          mid := (l + h) div 2;
-          if x = a[mid] then
-            exit(true)
-          else if x < a[mid] then
-            h := mid - 1
+          m := (l + h) div 2;
+          if x = a[m] then
+            exit(m)
+          else if x < a[m] then
+            h := m - 1
           else
-            l := mid + 1
+            l := m + 1
         end;
-
-      binin := false
+      bsearch := -1
     end;
 
 end.