Advertisement
marco15432

Untitled

Jan 12th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int banana(vector<vector<int> > grilla, int p, int q){
  6.  
  7. if(q == 0 || p == 0 || p == grilla.size() || q == grilla[0].size()){
  8.     return 0;
  9. }
  10. int posible1 = 0,posible2 = 0;
  11. int a = p, b = q;
  12. while(b < grilla[0].size()){
  13.     if(grilla[a][b] != 1){break;}
  14.     posible1 += 4;
  15.     b++;
  16. }
  17. b = q;
  18. while(b > -1){
  19.     if(grilla[a][b] != 1){break;}
  20.     posible2 += 4;
  21.     b--;
  22. }
  23. if(posible2 < posible1){
  24.     posible1 = posible2;
  25. }
  26. posible2 = 0;
  27.  
  28. b = q;
  29. while(a < grilla.size()){
  30.     if(grilla[a][b] != 1){break;}
  31.     posible1 += 4;
  32.     a++;
  33. }
  34. if(posible2 < posible1){
  35.     posible1 = posible2;
  36. }
  37. posible2 = 0;
  38.  
  39. a = p;
  40.  
  41. while(a > -1){
  42.     if(grilla[a][b] != 1){break;}
  43.     posible1 += 4;
  44.     a--;
  45. }
  46.  
  47. if(posible2 < posible1){
  48.     posible1 = posible2;
  49. }
  50. return posible1;
  51.  
  52.  
  53. }
  54.  
  55. int main()
  56. {
  57.  
  58.     int m,n;
  59.     cin >> m >> n;
  60.  
  61.     vector<vector<int> > grid (n);
  62.     vector<string> stars;
  63.  
  64.     int estrellasreales = 0;
  65.  
  66.     for(int i = 0; i < n; i ++){
  67.         for(int j = 0; j < m; j++){
  68.             char a;
  69.             cin >> a;
  70.             if(a == '*'){
  71.                 grid[i].push_back(1);
  72.                 estrellasreales++;
  73.             }
  74.             else{
  75.                 grid[i].push_back(0);
  76.             }
  77.         }
  78.     }
  79.     int estrellasrespresentables = 0;
  80.     for(int i = 0; i < n; i++){
  81.         for(int j = 0; j < m; j++){
  82.             int x = banana(grid,i,j);
  83.             if(x > 0){
  84.                 estrellasrespresentables++;
  85.                 string s;
  86.                 s[0] = 'i';s[1] = 'j'; s[2] = x;
  87.                 stars.push_back(s);
  88.             }
  89.         }
  90.     }
  91.  
  92.     if(estrellasreales <= estrellasrespresentables){
  93.         for(int i = 0; i < stars.size();i++){
  94.             cout << stars[i][0] << " " << stars[i][1] << " " << stars[i][2] << endl;
  95.         }
  96.  
  97.  
  98.         return 0;
  99.     }
  100.  
  101.     cout << -1;
  102.  
  103.  
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement