Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int main() {
- int redovi, koloni;
- cin >> redovi >> koloni;
- int matrica[redovi][koloni];
- int poseteno[redovi][koloni];
- int roboti = 0;
- int direction_i[] = {+1, -1, 0, 0};
- int direction_j[] = {0, 0, +1, -1};
- for(int i = 0; i < redovi; i++) {
- for(int j = 0; j < koloni; j++) {
- cin >> matrica[i][j];
- poseteno[i][j] = 0;
- }
- }
- for(int p = 0; p < 50; p++) {
- int najmal_broj = 50;
- int si, sj;
- for(int i = 0; i < redovi; i++) {
- for(int j = 0; j < koloni; j++) {
- if(najmal_broj > matrica[i][j] and poseteno[i][j] == 0) {
- najmal_broj = matrica[i][j];
- si = i;
- sj = j;
- }
- }
- }
- if(najmal_broj != 50) {
- queue<int> Q;
- Q.push(si);
- Q.push(sj);
- poseteno[si][sj] = 1;
- roboti++;
- while(!Q.empty()) {
- int ci = Q.front();
- Q.pop();
- int cj = Q.front();
- Q.pop();
- for(int k = 0; k < 4; k++) {
- int ti = ci + direction_i[k];
- int tj = cj + direction_j[k];
- if(ti >= 0 and ti < redovi and tj >= 0 and tj < koloni and poseteno[ti][tj] == 0 and matrica[ci][cj] <= matrica[ti][tj]) {
- Q.push(ti);
- Q.push(tj);
- poseteno[ti][tj] = 1;
- }
- }
- }
- }
- }
- cout << roboti << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement