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>
- 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++) {
- int pom;
- scanf("%d", &pom);
- gsl_matrix_set(mat, i, j, pom);
- }
- }
- gsl_matrix* nova_matrica = gsl_matrix_alloc((n + 2) / 2, (m + 2) / 2);
- int ni = 0;
- int nj = 0;
- for(int i = 0; i < n; i += 2) {
- nj = 0;
- for(int j = 0; j < m; j += 2) {
- int maks_sosed = gsl_matrix_get(mat, i, j);
- if(j + 1 < m) { // deka postoi sosedot koj e na desno od momentalnata kelija
- if(maks_sosed < gsl_matrix_get(mat, i, j + 1)) {
- maks_sosed = gsl_matrix_get(mat, i, j + 1);
- }
- }
- if(i + 1 < n) {
- if(maks_sosed < gsl_matrix_get(mat, i + 1, j)) {
- maks_sosed = gsl_matrix_get(mat, i + 1, j);
- }
- }
- if(i + 1 < n && j + 1 < m) {
- if(maks_sosed < gsl_matrix_get(mat, i + 1, j + 1)) {
- maks_sosed = gsl_matrix_get(mat, i + 1, j + 1);
- }
- }
- gsl_matrix_set(nova_matrica, ni, nj, maks_sosed);
- nj++;
- }
- ni++;
- }
- for(int i = 0; i < ni; i++) {
- for(int j = 0; j < nj; j++) {
- printf("%lf ", gsl_matrix_get(nova_matrica, i, j));
- }
- printf("\n");
- }
- }
- /*
- 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