2014 Beijing Network Competition instrusive HDU 5040 question solving priority queue

Source: Internet
Author: User

I read this question during the online competition and found that it is a common basic search question.

A special condition is added: It can consume 3 seconds at a time or stay in the same place for 1 second.

You cannot use a simple queue. You need to use a priority queue.


Question

Tell a map: a starting point, an ending point, several walls, several monitors, and the rest is the open space.


The start point, the end point, and the monitor are all empty spaces.

The initial value of the monitor specifies one direction, which has four directions.

The monitor rotates clockwise to the next direction every second.

Monitor field of view distance is 2.

The monitoring area is either in the monitor location or in the grid facing the monitor.


It takes 1 second to move a grid.

It takes 3 seconds to move a cell under the monitor.

If you stay in the same position, it will not be detected even in the monitor's field of view.


Obtain the minimum time from the start point to the end point.

Cannot reach output-1.


Ideas

The first step is to calculate whether it can reach the end point and move it directly under the monitor.

If we can reach the end point, we will start from the start point

Each vertex has three options in each direction, and the lattice will not be processed later.

1. Go directly

2. Go under the monitor

3. Stop for one second and then go directly.


If you can go directly, no other method will be selected, because it will reach the next position, and other methods will take longer.

It takes 1 second.


We can choose to go under the monitor when we cannot directly Leave.

It takes 3 seconds.

When we stop for one second, if we can go directly, let's go. If you cannot go directly, we will give up the one-second stop option.

Because one second is still under monitoring, you have to stop for another second or press monitoring. Neither of these two options will be better at monitoring at the very beginning.

It takes 2 seconds.


When we get the location and time of the next grid, we cannot mark the grid access immediately.

Because we use monitoring, there may be situations where we can go without monitoring.



Therefore, we have to first throw all the situations we encounter into the priority queue, and then make a judgment on the right.


For details, see the code.


For more information, see my GitHub (tiankonguse): https://github.com/tiankonguse/ACM/blob/master/hdu/5040.cpp


2014 Beijing Network Competition instrusive HDU 5040 question solving priority queue

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.