Topic links
Test instructions
There were n ants and M-Times asked
n Ants initially all at the beginning (0,0), every 4 ants in the same lattice will be the center of the lattice to climb up and down four directions in a grid
One up, one down, one left, one right.
If the number of ants in each lattice < 4, then the ant will stop the movement
Ask you when all the ants have stopped exercising, give you arbitrary (x, y), output the number of ants in the lattice
Ideas:
Simulation + violence
Because the query x, y will be negative, so it may be possible to set the starting coordinates (N,N), because the starting position of the ants at most also 30,000, so N no need to open to 1e9 so big, in fact 65 can be, the insurance to open 100, and then big Point estimated to tle;
When ABS (x) and abs (Y) > N are out of range, it must be 0;
Continuously traverse (2*n) * (2*n) of the lattice until there is not a lattice of ants >=4 so far.
The code is as follows:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 318D Ants