Advertisement
Josif_tepe

Untitled

Mar 30th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <gsl/gsl_matrix.h>
  4. #include <gsl/gsl_vector.h>
  5. int main() {
  6.     int n, m;
  7.     scanf("%d%d", &n, &m);
  8.     gsl_matrix * mat = gsl_matrix_alloc(n, m);
  9.     for(int i = 0; i < n; i++) {
  10.         for(int j = 0; j < m; j++) {
  11.             double t;
  12.             scanf("%lf", &t);
  13.             gsl_matrix_set(mat, i, j,  t);
  14.         }
  15.     }
  16.     int k;
  17.     scanf("%d", &k);
  18.     gsl_vector * V = gsl_vector_alloc(k);
  19.     for(int i = 0; i < k; i++) {
  20.         int pi, pj;
  21.         scanf("%d%d", &pi, &pj);
  22.        
  23.         if(pi + 1 < n && pj + 1 < m) {
  24.             double maks = gsl_matrix_get(mat, pi, pj);
  25.             if(maks < gsl_matrix_get(mat, pi + 1, pj)) {
  26.                 maks = gsl_matrix_get(mat, pi + 1, pj);
  27.             }
  28.             if(maks < gsl_matrix_get(mat, pi, pj + 1)) {
  29.                 maks = gsl_matrix_get(mat, pi, pj  + 1);
  30.             }
  31.             if(maks < gsl_matrix_get(mat, pi + 1, pj + 1)) {
  32.                 maks = gsl_matrix_get(mat, pi + 1, pj + 1);
  33.             }
  34.             gsl_vector_set(V, i, maks);
  35.         }
  36.         else {
  37.             gsl_vector_set(V, i, -1);
  38.         }
  39.     }
  40.     for(int i = 0; i < k; i++) {
  41.         printf("%.0lf ", gsl_vector_get(V, i));
  42.     }
  43. }
  44. /*
  45.  5 5
  46.  1 7 5 0 4
  47.  2 3 18 -3 5
  48.  14 0 7 5 2
  49.  3 3 4 5 6
  50.  7 0 0 1 2
  51.  
  52.  *.*/
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement