Created
May 2, 2017 22:01
-
-
Save pilifjed/a62a48e855f48203c45db7eb556375ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
void Init(int n, int t[n][n]){ | |
for(int i=0;i<n*n;i++){ | |
scanf("%d", &t[i/n][i%n]); | |
} | |
} | |
void PrintTab(int n, int t[n][n]){ | |
printf("\n"); | |
for (int i = 0; i < n;i++) | |
{ | |
for ( int j = 0; j < n;j++) | |
{ | |
printf("%i ",t[i][j]); | |
} | |
printf("\n"); | |
} | |
} | |
int Max(int x, int y){ | |
if(x>y) return x; | |
return y; | |
} | |
int Abs(int x){ | |
if(x>0) return x; | |
return -x; | |
} | |
int InRange(int x, int y, int j, int i, int r){ | |
if(Max(Abs(x-i),Abs(y-j))<=r) return 1; | |
return 0; | |
} | |
int InArray(int j, int i, int n){ | |
return i>=0 && j>=0 && i<n && j<n; | |
} | |
int SumRange(int n, int f[n][n], int r, int x, int y){ | |
int sum=0; | |
for(int i=x-r;i<n;i++){ | |
for(int j=y-r;j<n; j++){ | |
if(InArray(j,i,n)){ | |
if(InRange(x,y,j,i,r)) sum += f[i][j]; | |
else break; | |
} | |
} | |
} | |
return sum; | |
} | |
void RangeTab(int n, int f[n][n], int r){ | |
int w[n][n]; | |
for(int i=0;i<n;i++){ | |
for(int j=0;j<n;j++){ | |
w[i][j]=SumRange(n,f,r,i,j); | |
} | |
} | |
PrintTab(n,w); | |
} | |
int main(){ | |
int n, r; | |
scanf("%d", &n); | |
scanf("%d",&r); | |
int t[n][n]; | |
Init(n,t); | |
RangeTab(n,t,1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment