AIR PROBLEM - SOLUTION
The task was solved using vectors.
#include <iostream>
#include<vector>
using namespace std;
int main()
{
int bv,bk,in,pv,pk; /* bv-number of species, bk-number of columns, pv-move by species, pv-move by column*/
vector<vector<int>> trees;
cin>>bv>>bk;
for(int i=0;i<bv;i++){
vector<int>red;
for(int j=0;j<bk;j++){
cin>>in;
red.push_back(in);
}
trees.push_back(red);
}
cin>>pv>>pk;
int v=0,k=0,b=0;
while(!(v<0 || k<0 || v>=bv ||k>=bk)){ /*Checks if a field is inside an array*/
if(trees[v][k]==1){
b++;
}
v+=pv;
k+=pk;
}
cout<<b<<endl;
return 0;
}
#include<vector>
using namespace std;
int main()
{
int bv,bk,in,pv,pk; /* bv-number of species, bk-number of columns, pv-move by species, pv-move by column*/
vector<vector<int>> trees;
cin>>bv>>bk;
for(int i=0;i<bv;i++){
vector<int>red;
for(int j=0;j<bk;j++){
cin>>in;
red.push_back(in);
}
trees.push_back(red);
}
cin>>pv>>pk;
int v=0,k=0,b=0;
while(!(v<0 || k<0 || v>=bv ||k>=bk)){ /*Checks if a field is inside an array*/
if(trees[v][k]==1){
b++;
}
v+=pv;
k+=pk;
}
cout<<b<<endl;
return 0;
}
Return to the web page Preparation for district competitions