Блог пользователя Frenzy_Love

Автор Frenzy_Love, история, 10 месяцев назад, По-английски

/* for l = 8, r = 26 */

include

include

include

include

using namespace std; using L = long; using LL = long long;

int main() {

int t;
cin >> t;

while (t--) {

    LL l, r;
    cin >> l >> r;

     LL res = (r >= 2 * l) ? (r - 1) / 2 : (r - l);

    cout << res << endl;
 }

return 0;

} /* how it is so that the answer is not 18 but 12!??? thanks, */

  • Проголосовать: нравится
  • -14
  • Проголосовать: не нравится

»
10 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

you were wrong, you wrote that in the true case (r — 1), the place is (r — l), that's why you get 12

  • »
    »
    10 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    so if the machine compiles and executes the code, the answer is 12 which is correct and accepted, BUT, if I would be to do it with my own brain, I get 18, check this out: "LL res = (26 >= 2 * 8) ? (26-1)/2 : (26-8);" this is what my brain computes: is 26 bigger or equal than 16 ? if it's true: 12 for false: 18; it went accepted like this...should I stop doing push_ups while programming cause my eye bulges are popping red and I make the machine see floats ?

»
10 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It should be long long res = (r>=2*l)? (r-l) : (r-1)/2;