fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MaxR=50;
  5. const int MaxC=50;
  6. int people[MaxR][MaxC]={0};
  7. int save[MaxR][MaxC]={0};
  8. int R,C,k,m;
  9. void move(int people[MaxR][MaxC], int save[MaxR][MaxC], int k, int R, int C) {
  10.  
  11. for(int i=0;i<R;i++){
  12. for(int j=0;j<C;j++){
  13. int d=people[i][j]/k;
  14. if(j+1<C && people[i][j+1]>=0){
  15. save[i][j]-=d;
  16. save[i][j+1]+=d;
  17. }
  18. if(j-1>=0 && people[i][j-1]>=0){
  19. save[i][j]-=d;
  20. save[i][j-1]+=d;
  21. }
  22. if(i+1<R && people[i+1][j]>=0){
  23. save[i][j]-=d;
  24. save[i+1][j]+=d;
  25. }
  26. if(i-1>=0 && people[i-1][j]>=0){
  27. save[i][j]-=d;
  28. save[i-1][j]+=d;
  29. }
  30. }
  31. }
  32. for(int i=0;i<R;i++)
  33. for(int j=0;j<C;j++)
  34. people[i][j]=save[i][j];
  35. }
  36.  
  37.  
  38.  
  39. int main(){
  40. cin>>R>>C>>k>>m;
  41. for(int i=0;i<R;i++){
  42. for(int j=0;j<C;j++){
  43. cin>>people[i][j];
  44. save[i][j]=people[i][j];
  45. }
  46. }
  47. for(int x=1;x<=m;x++){
  48. move(people, save,k,R,C);
  49. }
  50.  
  51. //找最小
  52. int Min=people[0][0];
  53. for(int i=0;i<R;i++){
  54. for(int j=0;j<C;j++){
  55. if(people[i][j]<Min)
  56. if(people[i][j]!=-1)
  57. Min=people[i][j];
  58. }
  59. }
  60. cout<<Min<<"\n";
  61. //找最大
  62. int Max=people[0][0];
  63. for(int i=0;i<R;i++){
  64. for(int j=0;j<C;j++){
  65. if(people[i][j]>Max)
  66. Max=people[i][j];
  67. }
  68. }
  69. cout<<Max;
  70. return 0;
  71. }
Success #stdin #stdout 0s 5304KB
stdin
2 3 4 1
10 2 -1 
5 -1 2
stdout
2
7