#P1367. 蚂蚁
蚂蚁
Description
There are many ants on an infinitely long stick. Each ant has an initial position and an initial direction (no two ants share the same initial position). The ants move forward in their current direction at a speed of 1 unit per second. When two ants meet, they turn around (the turning time is negligible). Given the initial position and initial direction of each ant, please compute their positions and directions after seconds.
Input Format
The first line contains two space-separated integers (the number of ants and the time ).
Lines to each contain two integers. Line gives the initial position and initial direction of the -th ant ( means facing right, means facing left).
Output Format
Output lines, each containing two integers. The -th line represents the position and direction of the -th ant after seconds ( means facing left, means facing right, means currently turning).
4 1
1 1
5 1
3 -1
10 1
2 0
6 1
2 0
11 1
Hint
Constraints and Conventions
- For of the testdata, .
- For of the testdata, , .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号