AlenAntonelli

Vova and Train 1066/A

Oct 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. ///http://codeforces.com/contest/1066/problem/A
  2.  
  3. #include <iostream>
  4. using namespace std;
  5. int main()
  6. {
  7.     int L, V, a, b;
  8.    
  9.     int Q;
  10.     cin>>Q;
  11.     for (int i=0; i<Q; i++)
  12.     {
  13.         cin>>L>>V>>a>>b;
  14.        
  15.         int x = L/V;
  16.        
  17.         int T = (b-a+1);
  18.         int Tx = 0;
  19.        
  20.         if ( T >= V ) ///si es mas chico
  21.         {
  22.             Tx = T/V;
  23.            
  24.             int sobra = T%V; ///me sobran...
  25.             int LPR = b - sobra; ///me paro en la ultima pos del rango de tam multiplo de V
  26.             int falta = V - LPR%V; ///a esa ultima pos le faltan...
  27.            
  28.             if (sobra >= falta)
  29.                 Tx++;
  30.         }
  31.         else
  32.         {
  33.             if ( a <= b-(b%V) )
  34.                 Tx++;
  35.         }
  36.         cout<< x-Tx <<endl;
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment