博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVa 10557 - XYZZY
阅读量:4074 次
发布时间:2019-05-25

本文共 4354 字,大约阅读时间需要 14 分钟。

FILE 4446
23.50%
817
74.54%

题目链接

题目类型: 搜索

题目:

  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 the Y-Crate gaming device. A number of enterprising 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 is the start and one of the rooms is thefinish. Each room has an energy value between -100 and +100. One-way doorways interconnect pairs of rooms.

The player begins in the start room with 100 energy 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, receiving its energy each time.

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

  • the energy value for room i
  • the number of doorways leaving room i
  • a list of the rooms that are reachable by the doorways leaving room i
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".

                                                     

题目翻译:

背景:典型的电脑冒险游戏,最早出现在1970年代中期的PDP-10电脑(数字设备公司DEC生产的)上,是由Will Crowther设计的。这是一种尝试由电脑裁判的奇幻游戏。1976年在斯坦福大学的Don Woods把它拓展成一个拼图游戏(Don Woods是INTERCAL的作者之一)。现在更出名的是冒险或巨大的洞穴探险游戏。但是PDP-10的操作系统只允许6个大写字母的文件名。更多信息请查询vadding, Zork,和Infocom.
最近人们发现如何在Y-Crate游戏设备上运行开源软件。很多企业的设计师都有部署开发好的Advent-Style风格游戏在Y-Crate上。你的工作就是测试这些设计是否可能获胜的。
每场比赛由一组100个房间组成。其中一个房间是起点,另一个房间是终点。 每个房间有一个能量值 ,从 -100到+ 100。其中有一些只能单向行走的门把这些房间连接起来。
玩家开始时会自动获得100点能量值。 她可以通过单向房间门进入另一个门,并且可以任意重复次数进入一个房间,而且每次进入那个房间都可以获得那个能量值(正的能量值是增加她的能量,负值减少她的能量)。如果在能量用完(变为0或者负数)之前能够走到终点房间,那么就可以赢。否则,就是输。

样例输入:

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
样例输出:

hopelesshopelesswinnablewinnable

分析与总结:

这题首先想到的就是用深搜来做。

仔细分析题目可以看出, 可以重复进入一个房间,也就是可以任意次数来往两个房间。这样的话,这个游戏就有个“BUG”:只要有两个相连的房间(循环的), 例如,其中一个为10, 另一个为-2, 那么便可以反复来玩这两个房间,从而可以获得一个无限大的能量! 这样的话,如果可以找到通往终点的路,由于可以获得无限能量,那么就一定可以赢的!

利用这一点,在进行深搜时,一旦发现可以进入之前走过的房间(即有环图),那么就可以进行判断,是否可以获得无限能量。如果可以获得无限能量的话,就再从当前这点开始搜索,看看能否到达终点,如果可以的话,那么就直接判定为胜利!

在网上搜这题解题报告时,会发现很多都是用什么SPFA做的,其实用DFS+特判就可以了。

AC代码:

#include
#include
#include
#define INF 2147483646using namespace std;int nRoom, energy[105];struct Node{ int val; int nLeave; int reach[105];};Node room[105];bool vis[105], flag; int que[100000];// 这个搜索能获得无限能量的点能不能直接到达终点void bfs(int pos){ memset(vis, 0, sizeof(vis)); vis[pos] = true; int front=0, rear=1; que[0] = pos; while(front < rear){ int q = que[front++]; if(q == nRoom){ flag=true; return; } for(int i=0; i
=1 && m<=nRoom) { vis[m] = true; que[rear++] = m; } } }}void dfs(int pos, int val){ if(flag || pos<=0 || pos>nRoom) return; // printf("Room %d : left = %d\n", pos, val+room[pos].val); if(val <= 0) return; if(pos==nRoom && val>0) { flag = true; return; } for(int i=0; i
0){ energy[m] = val+room[m].val; dfs(m, val+room[m].val); } }}int main(){#ifdef LOCAL freopen("input.txt", "r", stdin);#endif while(~scanf("%d", &nRoom) && nRoom!=-1){ for(int i=1; i<=nRoom; ++i){ scanf("%d %d", &room[i].val, &room[i].nLeave); for(int j=0; j

——      生命的意义,在于赋予它意义。 
                   原创 
 , By   D_Double

转载地址:http://dyzni.baihongyu.com/

你可能感兴趣的文章
检测缓存文件是否超时
查看>>
十进制字符串转十六进制字符串
查看>>
属性字符串(富文本)的使用
查看>>
cell上label的背景颜色在选中状态下改变的解决办法
查看>>
GPS定位
查看>>
地图、显示用户位置、大头针
查看>>
自定义大头针
查看>>
UIButton添加block点击事件
查看>>
利用runtime给类别添加属性
查看>>
本地推送
查看>>
FMDB的使用
查看>>
UIImage存为本地文件与UIImage转换为NSData
查看>>
[转]打印质数的各种算法
查看>>
[转]javascript with延伸的作用域是只读的吗?
查看>>
php的autoload与global
查看>>
IE不支持option的display:none属性
查看>>
关于JQuery UI:dialog的isOpen API使用
查看>>
[分享]mysql内置用于字符串型ip地址和整数型ip地址转换函数
查看>>
TableDnd(JQuery表格拖拽控件)应用进阶
查看>>
[转]开源中最好的Web开发的资源
查看>>