Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <queue>
  7. using namespace std;
  8.  
  9. void rotApples(int **field, queue<pair<int,int>> &q, int m, int n, int e ){
  10. int size=q.size();
  11. for(int i=0; i<size; i++){
  12. int x1=q.front().first;
  13. int y1=q.front().second;
  14.  
  15. if(x1-1>=0 && x1-1<=n-1 && y1>=0 && y1<=m-1) {
  16. if(field[x1-1][y1]==0){
  17. q.push(make_pair(x1-1,y1));
  18. field[x1-1][y1]=e;
  19. }
  20. }
  21. if(x1+1>=0 && x1+1<=n-1 && y1>=0 && y1<=m-1) {
  22. if(field[x1+1][y1]==0){
  23. q.push(make_pair(x1+1,y1));
  24. field[x1+1][y1]=e;
  25. }
  26. }
  27. if(x1>=0 && x1<=n-1 && y1-1>=0 && y1-1<=m-1) {
  28. if(field[x1][y1-1]==0){
  29. q.push(make_pair(x1,y1-1));
  30. field[x1][y1-1]=e;
  31. }
  32. }
  33. if(x1>=0 && x1<=n-1 && y1+1>=0 && y1+1<=m-1) {
  34. if(field[x1][y1+1]==0){
  35. q.push(make_pair(x1,y1+1));
  36. field[x1][y1+1]=e;
  37. }
  38. }
  39. q.pop();
  40. }
  41. }
  42. int main() {
  43. int n, m, t, x, y, appleCount=0;
  44. cin>>n>>m>>t;
  45. int** field=new int*[n];
  46. for(int i=0; i <n; i++){
  47. field[i]=new int[m];
  48. }
  49. for(int i=0; i<n; i++){
  50. for(int j=0; j<m; j++){
  51. field[i][j]=0;
  52. }
  53. }
  54. queue <pair<int, int>> q;
  55. while(cin>>x>>y){
  56. q.push(make_pair(n-x,y-1));
  57. field[n-x][y-1]=8;
  58. }
  59. int e=1;
  60. for(int i=0; i<t; i++){
  61. rotApples(field, q, m, n, e);
  62. e++;
  63. }
  64.  
  65.  
  66. int plsCount=0;
  67. for(int i=0; i<n; i++){
  68. for(int j=0; j<m; j++){
  69. if(field[i][j]==0) plsCount++;
  70. }
  71. }
  72. cout<<plsCount;
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement