CCC '05 S2 - Mouse Move

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Canadian Computing Competition: 2005 Stage 1, Senior #2

Most likely, you will notice that you have a mouse attached to your computer, which lets you move the cursor around the screen. Your job is to get between the mouse and the cursor.

Suppose that the bottom left-hand corner of your screen is (0, 0)(0, 0), and all points on the screen are given by integer coordinates (x, y)(x, y) where 0 \le x \le c0 \le x \le c and 0 \le y \le r0 \le y \le r. Thus, the top-right corner of the screen is at position (c, r)(c, r), bottom-right corner is (c, 0)(c, 0), and top-left corner is (0, r)(0, r).

When a mouse is moved, it sends a pair of integers (a, b)(a, b), indicating that the cursor should be moved aa units in the x-direction and bb units in the y-direction. It is worth noting that this is relative motion (i.e., how far to move) rather than absolute motion (i.e., where to move). It is also worth noting that aa and bb may be positive, negative or zero.

You can assume the mouse starts at position (0, 0)(0, 0). Your job is to read input messages (i.e., relative motion positions sent by the mouse) and update the cursor to the new position on the screen. Your output (to the screen) will be the position of the mouse after each move.

If the mouse hits the screen boundary, it stops moving in that direction. For example, if the mouse is supposed to move (-100, -10)(-100, -10) from its current position (30, 40)(30, 40), the final positions will be (0, 30)(0, 30): the mouse will hit the left-hand side boundary, but still manages to move down.

Input is listed as pairs, the first pair being (c, r)(c, r), followed by the relative motion pairs (x, y)(x, y). The input is terminated when the mouse moves (0, 0)(0, 0).

Sample Input 1

100 200
10 40
-5 15
30 -30
0 0

Sample Output 1

10 40
5 55
35 25

Sample Input 2

30 40
30 40
-100 -10
0 0

Sample Output 2

30 40
0 30

CCC problem statements in large part from the PEG OJ


  • 1
    supriseyou123  commented on Feb. 10, 2019, 7:27 p.m.

    For some reason test case #5 does not work, every other test works. I tested my program multiple times and submitted many times but for some reason it doesn't work.

    • 1
      Julien  commented on Jan. 14, 2020, 3:22 p.m.

      Same for me, would you happen to know why?

      • 6
        hxxr  commented on Jan. 14, 2020, 5:45 p.m.

        Try this test case:

        1 2
        1 1
        0 1
        0 0

        The mouse should be able to move all the way to (1,2).

  • 0
    Cameron  commented on May 16, 2018, 12:17 p.m.

    Why can't I see my output for this problem?

  • 10
    quantum  commented on Nov. 1, 2014, 3:05 p.m.

    The problem has a trailing space in the first test case, biting all those that used .split(' '). This is now fixed.

    • 5
      richardyi25  commented on June 30, 2016, 9:10 p.m.

      It seems that Test Case #2 still has a leading space (I'm getting a ValueError if I don't .strip(' ') before .split(' '))

      • 10
        Xyene  commented on July 1, 2016, 12:15 a.m. edited

        Thanks for noticing, the testcase indeed had a trailing space. It's fixed now (and all submissions rejudged).