Advertisement
mickypinata

PROG-T1033: Conquerer

Mar 24th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. typedef struct pos{
  6.     int row;
  7.     int col;
  8. }pos;
  9.  
  10. pos ctrl[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; /// N E S W
  11. pos stand[5];
  12. vector<vector<int>> table;
  13. vector<vector<char>> mov(5);
  14. vector<int> score(5, 1);
  15. vector<int> winner;
  16. int t, r, c, mx, sum;
  17. char cmd;
  18.  
  19. void PrintTable(){
  20.     for(int i = 1; i <= t; ++i){
  21.         for(int j = 1; j <= t; ++j){
  22.             cout << table[i][j] << " ";
  23.         }
  24.         cout << "\n";
  25.     }
  26.     return;
  27. }
  28.  
  29. void PrintScore(){
  30.     cout << "Score\n";
  31.     for(int i = 1; i <= 4; ++i){
  32.         cout << score[i] << " ";
  33.     }
  34.     cout << "\n";
  35.     return;
  36. }
  37.  
  38. int main(){
  39.  
  40.     scanf("%d", &t);
  41.     table.assign(t + 1, vector<int>(t + 1, 0));
  42.     scanf("%d", &r);
  43.     table[1][t] = 1;
  44.     stand[1] = {1, t};
  45.     table[t][t] = 2;
  46.     stand[2] = {t, t};
  47.     table[t][1] = 3;
  48.     stand[3] = {t, 1};
  49.     table[1][1] = 4;
  50.     stand[4] = {1, 1};
  51.  
  52.     for(int i = 1; i <= 4; ++i){
  53.         for(int j = 0; j < r; ++j){
  54.             scanf(" %c", &cmd);
  55.             mov[i].push_back(cmd);
  56.         }
  57.     }
  58.  
  59.     for(int i = 0; i < r; ++i){
  60.         for(int p = 1; p <= 4; ++p){
  61.             cmd = mov[p][i];
  62.             switch(cmd){
  63.             case 'N':
  64.                 c = 0;
  65.                 break;
  66.             case 'E':
  67.                 c = 1;
  68.                 break;
  69.             case 'S':
  70.                 c = 2;
  71.                 break;
  72.             case 'W':
  73.                 c = 3;
  74.                 break;
  75.             }
  76.             if(stand[p].row + ctrl[c].row > 0 && stand[p].row + ctrl[c].row <= t && stand[p].col + ctrl[c].col > 0 && stand[p].col + ctrl[c].col <= t){
  77.                 bool pass = true;
  78.                 for(int j = 1; j <= 4; ++j){
  79.                     if(stand[p].row + ctrl[c].row == stand[j].row && stand[p].col + ctrl[c].col == stand[j].col){
  80.                         pass = false;
  81.                     }
  82.                 }
  83.                 if(pass){
  84.                     if(table[stand[p].row + ctrl[c].row][stand[p].col + ctrl[c].col] != 0){
  85.                         --score[table[stand[p].row + ctrl[c].row][stand[p].col + ctrl[c].col]];
  86.                     }
  87.                     table[stand[p].row + ctrl[c].row][stand[p].col + ctrl[c].col] = p;
  88.                     ++score[p];
  89.                     stand[p].row += ctrl[c].row;
  90.                     stand[p].col += ctrl[c].col;
  91.                 }
  92.             }
  93.         }
  94.     }
  95.  
  96.     mx = 0;
  97.     sum = 0;
  98.     for(int i = 1; i <= 4; ++i){
  99.         sum += score[i];
  100.         if(score[i] > mx){
  101.             winner.clear();
  102.             mx = score[i];
  103.             winner.push_back(i);
  104.         } else if(score[i] == mx){
  105.             winner.push_back(i);
  106.         }
  107.     }
  108.  
  109.     if(sum < t * t){
  110.         cout << "No";
  111.     } else {
  112.         cout << winner.size() << " " << mx << "\n";
  113.         for(auto x : winner){
  114.             cout << x << "\n";
  115.         }
  116.     }
  117.  
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement