Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- void rotApples(int **field, queue<pair<int,int>> &q, int m, int n, int e ){
- int size=q.size();
- for(int i=0; i<size; i++){
- int x1=q.front().first;
- int y1=q.front().second;
- if(x1-1>=0 && x1-1<=n-1 && y1>=0 && y1<=m-1) {
- if(field[x1-1][y1]==0){
- q.push(make_pair(x1-1,y1));
- field[x1-1][y1]=e;
- }
- }
- if(x1+1>=0 && x1+1<=n-1 && y1>=0 && y1<=m-1) {
- if(field[x1+1][y1]==0){
- q.push(make_pair(x1+1,y1));
- field[x1+1][y1]=e;
- }
- }
- if(x1>=0 && x1<=n-1 && y1-1>=0 && y1-1<=m-1) {
- if(field[x1][y1-1]==0){
- q.push(make_pair(x1,y1-1));
- field[x1][y1-1]=e;
- }
- }
- if(x1>=0 && x1<=n-1 && y1+1>=0 && y1+1<=m-1) {
- if(field[x1][y1+1]==0){
- q.push(make_pair(x1,y1+1));
- field[x1][y1+1]=e;
- }
- }
- q.pop();
- }
- }
- int main() {
- int n, m, t, x, y, appleCount=0;
- cin>>n>>m>>t;
- int** field=new int*[n];
- for(int i=0; i <n; i++){
- field[i]=new int[m];
- }
- for(int i=0; i<n; i++){
- for(int j=0; j<m; j++){
- field[i][j]=0;
- }
- }
- queue <pair<int, int>> q;
- while(cin>>x>>y){
- q.push(make_pair(n-x,y-1));
- field[n-x][y-1]=8;
- }
- int e=1;
- for(int i=0; i<t; i++){
- rotApples(field, q, m, n, e);
- e++;
- }
- int plsCount=0;
- for(int i=0; i<n; i++){
- for(int j=0; j<m; j++){
- if(field[i][j]==0) plsCount++;
- }
- }
- cout<<plsCount;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement