Codeforces 318D Ants

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.