fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int arr[105][105]={0};
  4. int h,w,k;
  5. void p(){
  6. for(int i=1;i<=h;i++){
  7. for(int j=1;j<=w;j++){
  8. if(arr[i-1][j-1]==-1 || arr[i+1][j-1]==-1 || arr[i-1][j+1]==-1 || arr[i+1][j+1]==-1){
  9. if(arr[i][j]!=1)arr[i][j]=-1;
  10. }
  11. }
  12. }
  13. int f=0;
  14. for(int i=1;i<=h;i++){
  15. for(int j=1;j<=w;j++){
  16. if(arr[i][j]==1){
  17. arr[i-1][j]=1;
  18. arr[i+1][j]=1;
  19. arr[i][j-1]=1;
  20. arr[i][j+1]=1;
  21. break;
  22. f=1;
  23. }
  24. }
  25. if(f==1)break;
  26. }
  27. }
  28. int main(){
  29. cin>>h>>w>>k;
  30. //input
  31. for(int i=1;i<=h;i++){
  32. for(int j=1;j<=w;j++){
  33. cin>>arr[i][j];
  34. }
  35. }
  36. //main
  37. for(int i=1;i<=k;i++){
  38. p();
  39. }
  40. for(int i=1;i<=h;i++){
  41. for(int j=1;j<=w;j++){
  42. cout<<arr[i][j]<<" ";
  43. }
  44. cout<<"\n";
  45. }
  46. }
  47.  
  48. /*
  49.  0 -1 0 -1 0
  50. -1 0 -1 0 1
  51.  0 -1 0 1 1
  52. -1 0 1 1 1
  53.  0 1 1 1 1 */
  54.  
Success #stdin #stdout 0.01s 5284KB
stdin
5 5 2
0 0 0 0 0
0 0 -1 0 0
0 0 0 0 0
0 0 0 1 0
0 0 0 0 0
stdout
0 -1 0 -1 0 
-1 0 -1 1 -1 
0 -1 1 1 1 
-1 1 1 1 1 
0 1 1 1 1