ch_dktomar's blog

By ch_dktomar, history, 3 months ago, In English

void solve() { int n, h, a, b, k; cin >> n >> h >> a >> b >> k;

for(int i = 0; i < k; i++) {
    int t1, f1, t2, f2;
    cin >> t1 >> f1 >> t2 >> f2;
    if(t1 == t2) {
        cout << std::abs(f1 - f2) << endl;
        continue;
    }
    const auto d1 = std::abs(f1 - a) + std::abs(a - f2);
    const auto d2 = std::abs(f1 - b) + std::abs(b - f2);
    cout << std::min(d1, d2) + std::abs(t1 - t2) << endl;
}

}

How can the above code fail for this problem

  • Vote: I like it
  • -3
  • Vote: I do not like it

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ch_dktomar (previous revision, new revision, compare).

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

try this test case

Spoiler
  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    3 is the answer I am getting.

    I will travel from (f3 -> f2) -> (t1 -> t2) -> (f2 -> f3)

    Seems to be a correct ans to me.

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      you can directly travel from tower $$$1$$$ floor $$$3$$$ to tower $$$2$$$ floor $$$3$$$, as $$$a = 2$$$ and $$$b = 4$$$

      • »
        »
        »
        »
        3 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Why don't I need to go to floor 2 or 4 from floor 3 of tower 1.

        • »
          »
          »
          »
          »
          3 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          well the point is to minimise the number of steps you take, so