Advertisement
FyanRu

Untitled

Jul 21st, 2024
185
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 1 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. using namespace std;
  5. #define MAX_N 10
  6.  
  7. int N, B[MAX_N][MAX_N];
  8.  
  9. bool color_appears(int c)
  10. {
  11.   for (int i=0; i<N; i++)
  12.     for (int j=0; j<N; j++)
  13.       if (B[i][j] == c) return true;
  14.   return false;
  15. }
  16.  
  17. // Is c1 "on top of c2" -- i.e., does c1 appear within the bounding box of c2?
  18. bool on_top_of(int c1, int c2)
  19. {
  20.   // Find c2's bounding box
  21.   int top=N, bottom=0, left=N, right=0;
  22.   for (int i=0; i<N; i++)
  23.     for (int j=0; j<N; j++)
  24.       if (B[i][j] == c2) {
  25.     top = min(top, i);
  26.     bottom = max(bottom, i);
  27.     left = min(left, j);
  28.     right = max(right, j);
  29.       }
  30.  
  31.   // Does c1 fall within it?
  32.   for (int i=top; i<=bottom; i++)
  33.     for (int j=left; j<=right; j++)
  34.       if (B[i][j] == c1) return true;
  35.  
  36.   return false;
  37. }
  38.  
  39. int main(void)
  40. {
  41.   ifstream fin ("art.in");
  42.   ofstream fout ("art.out");
  43.   fin >> N;
  44.   for (int i=0; i<N; i++) {
  45.     string s;
  46.     fin >> s;
  47.     for (int j=0; j<N; j++)
  48.       B[i][j] = s[j] - '0';
  49.   }
  50.  
  51.   int answer = 0;
  52.   for (int i=1; i<=9; i++)
  53.     if (color_appears(i)) {
  54.       bool could_be_first = true;
  55.       for (int j=1; j<=9; j++)
  56.     if (j!=i && color_appears(j) && on_top_of(i,j))
  57.       could_be_first = false;
  58.       if (could_be_first) answer++;
  59.     }
  60.  
  61.   fout << answer << "\n";
  62.   return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement