Brush over a question of the NOIP2007 Watchman's escape

Source: Internet
Author: User

The Demon Hunter was particularly ambitious. He betrayed the night elves, and the rate of the deep seabed was attempted mutiny: The watchman was killed in a clash 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, all the knives will be killed: The watchman's running speed, for 17m/s, at such a speed is unable to 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:

Only one row, including three non-negative integer m,s,t separated by a space.

Output:

Contains two lines:
The 1th behavior string "Yes" or "No" (case-sensitive), that is, whether the watcher can escape from the desert island.
Line 2nd 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.

Input Example:

39 200 4

Output Example:

No
197

Limitations: 30% Data: 1 <= t<=, 1 <=s<= 100, 50% data satisfied: 1 <= T <=, 1 <= S <= 10000;100% data: 1 < = T <= 300000, 0 <= m<=1000 1 <=s <= 10^8

The standard method of this problem is to move, but I still use greed. Since I use the greedy AC, naturally have the beauty of greed--please appreciate.

1#include <iostream>2 using namespacestd;3 intm,s,t,ans,temp;4 intMain ()5 {6Cin>>m>>s>>T;7     inttt=t;//We're going to use TT to store the initial time to calculate the difference8      while(t--)//Greedy9     {Ten         if(m>=Ten) m-=Ten, ans+= -;//priority is given to flashing One         Elsem+=4; Atemp+= -;//ideal for storing walking distances for easy comparison of flicker and walk -         if(ans>temp) Temp=ans;//if the flicker is farther than the walk, then the distance between the two is exchanged -         if(Temp>s) Break;//If you escape, take the shortest time. the     } -     if(temp>=s&&t>=0) cout<<"Yes"<<endl<<tt-t;//Judging whether you have fled -     Elsecout<<"No"<<endl<<temp; -     //System ("Pause>nul"); +     return 0; -}
C + + answer

Brush over a question of the NOIP2007 Watchman's escape

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.