Ultraviolet A 10557 xy133

Source: Internet
Author: User

The questions are as follows:

Problem D: xy.pdf
ADVENT: /ad?vent/, n.
The prototypical computer adventure game, first designed by Will Crowther on the PDP-10 in the mid-1970s as an attempt at computer-refereed fantasy gaming, and expanded into a puzzle-oriented game by Don woods at Stanford in 1976. (woods had been one of the authors of intercal .) now better known as adventure or colossal cave adventure, but the tops-10 Operating System permitted only six-letter filenames in uppercase. see also vadding, Zork, and Infocom.

It has recently been discovered how to run open-source software on theY-crate gaming device. A number of parameter Ising designers have developedAdvent-Style games for deployment on the Y-crate. Your jobis to test a number of these designs to see which are winnable.

Each game consists of a set of up to 100 rooms. One of therooms isStartAnd one of the rooms isFinish. Each room hasENERGY VALUEBetween-100 and + 100. One-way doorways interconnect pairs of rooms.

The player begins in the Start room with 100Energy points. She maypass through any doorway that connects the room she is in to another room, thusentering the other room. the energy value of this room is added tothe player's energy. this process continues until she wins by enteringthe finish room or dies by running out of energy (or quits in frustration ). during her adventurethe player may enter the same room several times, refreshing ing its energyeach time.

The input consists of several test cases. Each test case beginsN, The number of rooms. The rooms are numbered from 1 (the start room)N(The finish room). Input forNRooms follows. The input for each room consists of one or more lines containing:

  • The energy value for roomI
  • The number of doorways leaving roomI
  • A list of the rooms that are reachable by the doorways leaving roomI
The start and finish rooms will always have enery level 0. A line containing-1 follows the last test case.

In one line for each case, output "winnable" if it is possible forthe player to win, otherwise output "hopeless ".

Sample Input
50 1 2-60 1 3-60 1 420 1 50 050 1 220 1 3-60 1 4-60 1 50 050 1 221 1 3-60 1 4-60 1 50 050 1 220 2 1 3-60 1 4-60 1 50 0-1
Output for sample input
hopelesshopelesswinnablewinnable

Ask if one point is reachable to another. Each point has a power value (energy), which requires that the energy and always be greater than 0, and there may be circles. The longest path can be obtained using the spfa Algorithm without any loops. If the longest path is greater than 0, the result is successful. In the case of circles, spfa can determine the outbound circle (if the total number of nodes is greater than N, it indicates that there is a circle). If the positive circle is generated (the negative circle is ignored directly, because it is not silly to take the negative circle to reduce the energy), and the point that generates the positive circle can reach the end point (directly DFS) without considering the energy, you can judge as successful. Otherwise, it fails. In other cases, either the vertex cannot reach the destination or the energy is not satisfied.

The AC code is as follows;


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.