Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int banana(vector<vector<int> > grilla, int p, int q){
- if(q == 0 || p == 0 || p == grilla.size() || q == grilla[0].size()){
- return 0;
- }
- int posible1 = 0,posible2 = 0;
- int a = p, b = q;
- while(b < grilla[0].size()){
- if(grilla[a][b] != 1){break;}
- posible1 += 4;
- b++;
- }
- b = q;
- while(b > -1){
- if(grilla[a][b] != 1){break;}
- posible2 += 4;
- b--;
- }
- if(posible2 < posible1){
- posible1 = posible2;
- }
- posible2 = 0;
- b = q;
- while(a < grilla.size()){
- if(grilla[a][b] != 1){break;}
- posible1 += 4;
- a++;
- }
- if(posible2 < posible1){
- posible1 = posible2;
- }
- posible2 = 0;
- a = p;
- while(a > -1){
- if(grilla[a][b] != 1){break;}
- posible1 += 4;
- a--;
- }
- if(posible2 < posible1){
- posible1 = posible2;
- }
- return posible1;
- }
- int main()
- {
- int m,n;
- cin >> m >> n;
- vector<vector<int> > grid (n);
- vector<string> stars;
- int estrellasreales = 0;
- for(int i = 0; i < n; i ++){
- for(int j = 0; j < m; j++){
- char a;
- cin >> a;
- if(a == '*'){
- grid[i].push_back(1);
- estrellasreales++;
- }
- else{
- grid[i].push_back(0);
- }
- }
- }
- int estrellasrespresentables = 0;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < m; j++){
- int x = banana(grid,i,j);
- if(x > 0){
- estrellasrespresentables++;
- string s;
- s[0] = 'i';s[1] = 'j'; s[2] = x;
- stars.push_back(s);
- }
- }
- }
- if(estrellasreales <= estrellasrespresentables){
- for(int i = 0; i < stars.size();i++){
- cout << stars[i][0] << " " << stars[i][1] << " " << stars[i][2] << endl;
- }
- return 0;
- }
- cout << -1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement