UVA 10557 XYZZY
Problem D: XYZZY
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 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 the finish. Each room has anenergy 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".
Sample Input
5
0 1 2
-60 1 3
-60 1 4
20 1 5
0 0
5
0 1 2
20 1 3
-60 1 4
-60 1 5
0 0
5
0 1 2
21 1 3
-60 1 4
-60 1 5
0 0
5
0 1 2
20 2 1 3
-60 1 4
-60 1 5
0 0
-1
Output for Sample Input
hopeless
hopeless
winnable
winnable
题意: 给定n,表示有n个房间,接下去输入n个房间的信息。信息有: 进入该房间会得到(失去)多少HP。和该房间能通到哪些房间。。初始血量为100,血量为0就死了,要求出能否从房间1走到房间n。 如果不能走到就输出hopeless,如果能就输出winnable。
思路: 注意这个游戏是有BUG的,比如如果在两个房间之间来回走可以回血,就可以把血量补到无穷大。。
这样判断,如果遇到回路,并且走完过回路会加血。。并且有路可以到终点房间,就是winnable。
如果回路走完加血量为0或者扣血了。。这条回路就没必要走。。
因此,思路即可以转换为:如果找到一条回路可以补血,并且可以走到终点。或者可以走到终点血量不为0.就输出winnable。
就用个搜索先把回路找出来。。如果有可以补血的回路,在从该点搜索能不能到终点。就成功了。。
#include <stdio.h>
#include <string.h> int n;
int judge;
int vis[105];
int hpp[105];
struct R
{
int hp;
int num;
int troom[105];
} room[105]; void dfs2(int fang)
{
if (fang == n)
{
judge = 1;
return;
}
for (int i = 0; i < room[fang].num; i ++)
{
int m = room[fang].troom[i];
if (vis[m] == 0)
{
vis[m] = 1;
dfs2(m);
vis[m] = 0;
}
}
}
void dfs(int xue, int fang)
{
if (judge)
return;
if (xue <= 0)
return;
if (fang == n && xue > 0)
{
judge = 1;
return;
}
for (int i = 0; i < room[fang].num; i ++)
{
int m = room[fang].troom[i];
if (hpp[m] && hpp[m] < xue + room[m].hp)
{
dfs2(fang);
if (judge)
return;
}
if (!hpp[m] && xue + room[m].hp > 0)
{
hpp[m] = xue + room[m].hp;
dfs(xue + room[m].hp, m);
}
}
} int main()
{
while (scanf("%d", &n) != EOF && n != -1)
{
judge = 0;
memset(room, 0, sizeof(room));
memset(vis, 0, sizeof(vis));
memset(hpp,0,sizeof(hpp));
hpp[1] = 100;
for (int i = 1; i <= n; i ++)
{
scanf("%d%d", &room[i].hp, &room[i].num);
for (int j = 0; j < room[i].num; j ++)
scanf("%d", &room[i].troom[j]);
}
dfs(100, 1);
if (!judge)
printf("hopeless\n");
else
printf("winnable\n");
}
return 0;
}
UVA 10557 XYZZY的更多相关文章
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
随机推荐
- datareader 和dataset 区别
ADO.NET2.0提供了两个用于检索关系数据的对象:DataSet和DataReader.并且这两个对象都可以将检索的关系数据存储在内存中.在软件开发过程中经常用到这两个控件,由于这两个控件在使用和 ...
- 上传文件格式控制的困惑(application/octet-stream 限制不了BAT等格式上传)问题解决
允许上传类型部分代码 $uptypes=array( //上传文件类型列表 'image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image ...
- C语言面向对象的简便方法
都知道C语言是面向过程的,但是现在软件规模越来越大,通过面向对象的方式可以简化开发.业余时间想了个简单的方法,在C中使用一部分面向对象的基本功能.由于C语言自身的限制,并不完善,只能将就用,聊胜于无, ...
- su: Bad item passed to pam_*_item()
su: Bad item passed to pam_*_item() 查看 /etc/default/locale 该文件应该只含义如下格式的文字: LANG=en_US.UTF-8 如何还没有解决 ...
- WordPress标题函数wp_title()详解
在wp_title()中通常是在页面头部的title元素中.当wp_title()在主页主循环(loop)外时,可以用在模板的任何地方. 用法: <?php wp_title( $sep, $e ...
- htm、html、shtml区别
htm.html.shtml都是静态网页的后缀,三者也可以说都是只是扩展名不同,其他一样,都是静态的网页. htm和html是完全静态的网页不通过服务器编译解释直接送出给浏览器读取的静态网页,以htm ...
- check、continue、exit的区别
DATA:BEGIN OF lt_table OCCURS 0, i_row TYPE i, i_col TYPE i, END OF lt_table. lt_t ...
- Spring 自动装配
1.自动装配有 bytype 和byName两种模式. 2.可以使用autowire属性指定自动装配的方式,byName根据bean的名称和当前bean的setter风格属性进行自动装配:byType ...
- 【网络流24题】 No.6 最长不减子序列问题 (最大流)[模型:最多不相交路径]
[题意] 给定正整数序列x1 ,x2 , x3... ( 1)计算其最长不减子序列的长度 s.( 2)计算从给定的序列中最多可取出多少个长度为 s 的不减子序列.( 3) 如果允许在取出的序列中多次使 ...
- 使用API网关构建微服务
使用传统的异步回调方法编写API组合代码会让你迅速坠入回调地狱.代码会变得混乱.难以理解且容易出错.一个更好的方法是使用响应式方法以一种声明式样式编写API网关代码.响应式抽象概念的例子有Scala中 ...