Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <gsl/gsl_matrix.h>
- #include <gsl/gsl_vector.h>
- int main() {
- int n, m;
- scanf("%d%d", &n, &m);
- gsl_matrix * mat = gsl_matrix_alloc(n, m);
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- double t;
- scanf("%lf", &t);
- gsl_matrix_set(mat, i, j, t);
- }
- }
- int k;
- scanf("%d", &k);
- gsl_vector * V = gsl_vector_alloc(k);
- for(int i = 0; i < k; i++) {
- int pi, pj;
- scanf("%d%d", &pi, &pj);
- if(pi + 1 < n && pj + 1 < m) {
- double maks = gsl_matrix_get(mat, pi, pj);
- if(maks < gsl_matrix_get(mat, pi + 1, pj)) {
- maks = gsl_matrix_get(mat, pi + 1, pj);
- }
- if(maks < gsl_matrix_get(mat, pi, pj + 1)) {
- maks = gsl_matrix_get(mat, pi, pj + 1);
- }
- if(maks < gsl_matrix_get(mat, pi + 1, pj + 1)) {
- maks = gsl_matrix_get(mat, pi + 1, pj + 1);
- }
- gsl_vector_set(V, i, maks);
- }
- else {
- gsl_vector_set(V, i, -1);
- }
- }
- for(int i = 0; i < k; i++) {
- printf("%.0lf ", gsl_vector_get(V, i));
- }
- }
- /*
- 5 5
- 1 7 5 0 4
- 2 3 18 -3 5
- 14 0 7 5 2
- 3 3 4 5 6
- 7 0 0 1 2
- *.*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement