Ultraviolet A 10557-xy133

Source: Internet
Author: User
Document directory
  • Sample Input
  • Output for sample input
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
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 the Y-crate gaming device. A number of parameter Ising designers have developed
Advent-Style games for deployment on the Y-crate. Your job is 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 the rooms isStartAnd one of the rooms is
Finish. 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 may pass through any doorway that connects the room she is in to another room, thus entering the other room. the energy value of this room is added to the player's energy. this process
Continues until she wins by entering the finish room or dies by running out of energy (or quits in frustration ). during her adventure the player may enter the same room several times, processing ing its energy each 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 for the 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
The initial energy value of hopelesshopelesswinnablewinnable is 100. If you have not walked through a room and added the energy value of the room, you can ask whether the energy value is equivalent to the edge weight from the start point to the end point, the original problem is equivalent to finding whether the distance between two points is greater than 0,
The difficulty lies in the presence of positive and negative loops. Refer to others' solutions 1. if a positive ring exists and the endpoint is reached, win. Otherwise, follow the common practice. spfa: to avoid the occurrence of positive loops but cannot reach the end point, you must set a maximum number of cycles for the spfa endless loop. In a word, they all look at other people and water them.
# Include <stdio. h> int I, j, M, X, F, k, n, top, tail, Q [100], visit [101], low [101], energy [101], map [101] [101]; int main () {While (scanf ("% d", & N) {If (n =-1) break; for (I = 1; I <= N; I ++) for (j = 1; j <= N; j ++) map [I] [J] = 0; for (I = 1; I <= N; I ++) {scanf ("% d ", & Energy [I], & M); For (j = 1; j <= m; j ++) {scanf ("% d", & X ); map [I] [x] = 1 ;}}for (I = 1; I <= N; I ++) {visit [I] = 1; low [I] = 0;} visit [1] = 0; low [1] = 100; Q [0] = 1; Top = 0; tail = 1; f = 0; M = 0; while (top! = Tail) {for (I = 1; I <= N; I ++) if (Map [Q [Top] [I] = 1) & (low [Q [Top] + energy [I]> low [I]) {LOW [I] = low [Q [Top] + energy [I]; If (visit [I] = 1) // start to put this condition together with the above if. This condition is not marked every time you join the queue. During each relaxation operation, no matter whether the {q [tail] = I is marked or not; tail = (tail + 1) % 100; visit [I] = 0; ++ M ;}} visit [Q [Top] = 1; Top = (top + 1) % 100; If (low [N]> 0) {f = 1; break ;}} if (F = 1) printf ("winnable \ n "); else printf ("hopeless \ n");} return 0 ;}

 
 

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.