Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. void ProcessOneTest(size_t number_of_test) {
  6.         size_t rows, colums, escape;
  7.         std::cin >> rows >> colums >> escape;
  8.         if (escape == rows*colums - 1) {
  9.             std::cout << "Case #" << number_of_test << ": "<< "IMPOSSIBLE\n";
  10.             return;
  11.         }
  12.         if (colums == 1) {
  13.             std::cout << "Case #" << number_of_test << ": "<< "POSSIBLE\n";
  14.             for (size_t index = 0; index < rows - escape; ++index) {
  15.                 if (index != rows - escape - 1) {
  16.                     std::cout << "S\n";
  17.                 } else {
  18.                     std::cout << "N\n";
  19.                 }
  20.             }
  21.             for (size_t index = rows - escape; index < rows; ++index) {
  22.                 std::cout << "S\n";
  23.             }
  24.             return;
  25.         }
  26.         std::vector<std::vector<char>> doors(rows, std::vector<char>(colums, ' '));
  27.         size_t id = 0;
  28.         do {
  29.             if (escape < colums) {
  30.                 break;
  31.             }
  32.             escape -= colums;
  33.             for (size_t index = 0; index < colums; ++index) {
  34.                 doors[id][index] = 'E';
  35.             }
  36.             ++id;
  37.         } while (true);
  38.         if (escape != 0) {
  39.             if (escape != colums - 1) {
  40.                 for (size_t index = 0; index < colums - escape; ++index) {
  41.                     if (index != colums - escape - 1) {
  42.                         doors[id][index] = 'E';
  43.                     } else {
  44.                         doors[id][index] = 'W';
  45.                     }
  46.                 }
  47.                 for (size_t index = colums - escape; index < colums; ++index) {
  48.                     doors[id][index] = 'E';
  49.                 }
  50.                 ++id;
  51.             } else {
  52.                 for (size_t index = 1; index < colums; ++index) {
  53.                     doors[id][index] = 'E';
  54.                 }
  55.                 doors[id][0] = 'S';
  56.                 ++id;
  57.                 doors[id][0] = 'N';
  58.                 for (size_t index = 1; index < colums; ++index) {
  59.                     if (index != colums - 1) {
  60.                         doors[id][index] = 'E';
  61.                     } else {
  62.                         doors[id][index] = 'W';
  63.                     }
  64.                 }
  65.                 ++id;
  66.             }
  67.         }
  68.         while (id != rows) {
  69.             for (size_t index = 0; index < colums; ++index) {
  70.                 if (index != colums - 1) {
  71.                     doors[id][index] = 'E';
  72.                 } else {
  73.                     doors[id][index] = 'W';
  74.                 }
  75.             }
  76.             ++id;
  77.         }
  78.         std::cout << "Case #" << number_of_test << ": POSSIBLE\n";
  79.         for (size_t index_first = 0; index_first < rows; ++index_first) {
  80.             for (size_t index_second = 0; index_second < colums; ++index_second) {
  81.                 std::cout << doors[index_first][index_second];
  82.             }
  83.             std::cout << '\n';
  84.         }
  85. }
  86.  
  87. int main() {
  88.     std::ios_base::sync_with_stdio(false);
  89.     std::cin.tie(nullptr);
  90.     size_t t;
  91.     std::cin >> t;
  92.     for (size_t number_of_test = 1; number_of_test <= t; ++number_of_test) {
  93.         ProcessOneTest(number_of_test);
  94.     }
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement