Advertisement
Nita_Cristian

hambar2 - histograma

Feb 26th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("hambar2.in");
  6. ofstream fout("hambar2.out");
  7.  
  8. int n, m, a[1010][1010];
  9.  
  10. void histograma()
  11. {
  12.     for (int j = 1; j <= m; j++) /// iau fiecare coloana in parte
  13.     {
  14.         stack<int> s;
  15.         s.push(0);
  16.  
  17.         a[n + 1][j] = 1; /// pun un pom sa il fortez sa imi calculeze cand ajung pe ultima linie
  18.  
  19.         for (int i = 1; i <= n + 1; i++) /// iau fiecare linie si parcurg toate celulele de pe coloana j
  20.         {
  21.             if (a[i][j]) /// daca am pom il marchez cu 0 (e o gaura, nu ma intereseaza)
  22.                 a[i][j] = 0;
  23.             else
  24.                 a[i][j] = a[i][j - 1] + 1; /// altfel el va deveni anterior + 1 ceea ce inseamna ca pot continua o zona
  25.  
  26.             while (a[i][j] < a[s.top()][j]) /// in stiva voi avea indicii unor valori care sunt in ordine crescatoare s: 5 4 3 2 1
  27.             {
  28.                 int latime = a[s.top()][j]; /// latimea va fi zona curenta
  29.                 s.pop();
  30.  
  31.                 int arie = latime * (i - 1 - s.top()); /// asta nu il inteleg
  32.             }
  33.             s.push(i); /// la final adaug indicele elementului
  34.         }
  35.     }
  36. }
  37.  
  38. int main()
  39. {
  40.     fin >> n >> m;               /// citesc dimensiunile matricii
  41.     for (int i = 1; i <= m; i++) /// citesc coordonatele pomilor
  42.     {
  43.         int x, y;
  44.         fin >> x >> y;
  45.         a[x][y] = 1; /// marchez pomul
  46.     }
  47.  
  48.     histograma();
  49.  
  50.     fin.close();
  51.     fout.close();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement