From 2f674dc80f0382f1c3178f435714960734dc9d3c Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sat, 6 Jun 2020 21:33:13 +0700 Subject: Reorganize stuff from secondary school --- 12/TP-HN-2008/R2/hc.cpp | 73 ------------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 12/TP-HN-2008/R2/hc.cpp (limited to '12/TP-HN-2008/R2/hc.cpp') diff --git a/12/TP-HN-2008/R2/hc.cpp b/12/TP-HN-2008/R2/hc.cpp deleted file mode 100644 index 1ea6ee3..0000000 --- a/12/TP-HN-2008/R2/hc.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include -#include - -#define ENC(a, x, y) (((a) << 16) + ((x) << 8) + (y)) - -using namespace std; - -int -main() -{ - long long m, n, i, j, a[200][200]; - ifstream infile; - infile.open("HC.INP"); - infile >> m >> n; - for (i = 0; i < m; i++) - for (j = 0; j < n; j++) - infile >> a[i][j]; - infile.close(); - - priority_queue, greater> heap; - long long path[200][200] = {}; - for (i = 0; i < m; i++) - { - heap.push(ENC(*a[i], i, 0)); - path[i][0] = 1; - } - - long long tmp, x, y; - while (!heap.empty()) - { - tmp = heap.top(); - heap.pop(); - x = tmp >> 8 & 255; - y = tmp & 255; - tmp >>= 16; - if (y == n - 1) - break; - - if (!path[x][y + 1]) - { - heap.push(ENC(tmp + a[x][y + 1], x, y + 1)); - path[x][y + 1] = 1; - } - - if (y) - if (x && !path[x - 1][y]) - { - heap.push(ENC(tmp + a[x - 1][y], x - 1, y)); - path[x - 1][y] = 1; - } - else if (x < m - 1 && !path[x + 1][y]) - { - heap.push(ENC(tmp + a[x + 1][y], x + 1, y)); - path[x + 1][y] = 1; - } - - if (y > 1 && !path[x][y - 1]) - { - heap.push(ENC(tmp + a[x][y - 1], x, y - 1)); - path[x][y - 1] = 1; - } - } - - ofstream outfile; - outfile.open("HC.OUT"); - outfile << tmp << endl; - outfile.close(); - - return 0; -} -- cgit 1.4.1