The Watchman's escape (3rd in the 2007 universal group) | Greedy algorithm

Source: Internet
Author: User

The Watchman's escape (3rd question of the 2007 universal group)

"Problem description"

The Demon Hunter, Dean, was ambitious and betrayed the night elves, who had been buried in the sea and attempted to mutiny, and the Watchmen had been killed in the confrontation with Illidan. Trapped on a deserted Big island. In order to kill the Watchman, Dean began to curse the island, the island will soon sink, until then everyone on the island will be killed: The Watcher's running speed is 17m/s, at such a speed can not escape the desert island. Fortunately, the watcher has a flashing spell that can move 60m within 1s, but each use of a flashing spell consumes a mana value of 10 points. The Catcher's Mana recovery rate is 4 points/s, which can only be restored when in-situ resting state.

Now known as the Watcher's magical initial value m, the distance between his initial position and the island's exit S, the island sank time t. Your task is to write a program to help the watcher calculate how to escape from the desert island in the shortest time, if not escape, then the output watcher in the remaining time to walk the farthest distance. Note: The watcher's running, flashing, or resting activities are in seconds (s). and the duration of each activity is an integer second. The unit of distance is in meters (m).

"Input File"

The input file escape.in only one line, including three non-negative integer m,s,t separated by spaces.

"Output File"

The output file Escape.out contains two lines:

The 1th behavior string "Yes" or "No" (case-sensitive), that is, whether the watcher can escape from the desert island.

The 2nd line contains an integer, the first Behavior "Yes" (case-sensitive) indicates the shortest time to flee the desert island the first behavior "No" (case-sensitive) indicates the maximum distance the watcher can walk.

Example 1 input "Sample 1 Output"

4 No

197

Example 2 Input "Sample 2 Output"

255 Ten Yes

6

Analysis

Just read the question, the amount ... This relationship is a bit messy = = then quickly test instructions ...

This call catcher's big recruit is a second move 60 meters, walk a second move 17 meters, enlarge recruit to 10 MP, MP only in meditation (not move) when can restore, and a second restore 4 points, ask in the specified time can run to a certain distance.

If the MP is infinite, the skill must run fast. And now only the M-point MP, you may want to think about when the MP consumption after the recovery is cost-effective or always run.

Obviously, when the MP remaining is 0 or 1 o'clock, it takes 3 seconds to restore the skill + 1 seconds to release the skill, can move 60 meters, and the simple movement can move 17*4 = 68 meters,

When MP > 1 o'clock requires up to 2 seconds of recovery skill + 1 seconds to release the skill can move 60 meters, while the simple move can move 17*3 = 51 meters.

So you just have to put the skill on until the remaining distance is 68 meters and the remaining time is enough to release the skill.

1#include <cstdio>2 3 intMain () {4     intM, S, t, sum =0;5scanf" %d%d%d", &m, &s, &t);6      for(inti =1; I <= t; i++) {7         if(M >=Ten) {8Sum + = -;9M-=Ten;Ten}Else  if(((Ten-m)%4==0? (Ten-m)/4: (Ten-m)/4+1) <= t-i && s-sum >= the)  { OneM + =4; A}Else { -Sum + = -; -         } the         if(Sum >=s) { -printf"yes\n%d", i); -             return 0; -         } +     } -printf"no\n%d", sum); +}
Simulation Process Code

"The last point of the spit"

Why did the warden flee? Because the island will sink.

What happens when the island sinks? The watchman will be drowned.

What happens when you run off the island? The Guardian fell into the water.

The Watchman's escape (3rd in the 2007 universal group) | Greedy algorithm

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.