Advertisement
AlenAntonelli

Rope folding

Jul 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. /// https://www.hackerrank.com/contests/simulacro-oia-4-1/challenges/problem-0-rope-folding
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n, l, c=0;
  10.     cin>>n>>l;
  11.    
  12.     vector<bool> v (l+1);
  13.    
  14.     int pos;
  15.     for (int i=0; i<n; i++)
  16.     {
  17.         cin>>pos;
  18.         v[pos] = true;
  19.     }
  20.    
  21.     for (float q=1; q<l; q+=(0.5))
  22.     {
  23.         int centro = 2*q, ini=centro/2, fin=centro/2;
  24.         if ( centro%2 == 1 )
  25.             ini++; ///cout<<q<<" : "<<ini<<" "<<fin<<endl;
  26.        
  27.         bool es = true;
  28.        
  29.         while ( ini>0 && fin<l )
  30.         {
  31.             ini--;
  32.             fin++;
  33.            
  34.             if ( v[ini] != v[fin] )
  35.                 es = false;
  36.         }
  37.        
  38.         if (es)
  39.             c++;
  40.     }
  41.    
  42.     cout<<c;
  43.        
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement