XYZZY
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 4154   Accepted: 1185

Description

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 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.

Input

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.

Output

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

Sample Output

hopeless
hopeless
winnable
winnable

Source

题目意思:
n个点,每个点有一个权值,存在负权值
构成一个有向图,点从1到n编号,起点是1,终点是n
起点和终点的权值都为0
每个点可以走多次
现在又一个人,从起点开始走,他开始具有100的能量,走到一个点,就加上这个点的权值
如果能量小于等于0的话就会死去,不能到达终点
问你他是否可以到达终点
分析:
每个点可以走多次,意味着只要存在正环且正环上的某个点到n是可达的(所以需要求传递闭包)
那么他一定可以到达n点,这是第一种情况
第二种情况就是跑个最长路,然后dis[n]是大于0的
这两种情况都是可以到达n的
注意最长路dis初始化0......
 
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<set>
#include<map>
#include<list>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 99999999
#define me(a,x) memset(a,x,sizeof(a))
int mon1[]= {,,,,,,,,,,,,};
int mon2[]= {,,,,,,,,,,,,};
int dir[][]= {{,},{,-},{,},{-,}}; int getval()
{
int ret();
char c;
while((c=getchar())==' '||c=='\n'||c=='\r');
ret=c-'';
while((c=getchar())!=' '&&c!='\n'&&c!='\r')
ret=ret*+c-'';
return ret;
}
void out(int a)
{
if(a>)
out(a/);
putchar(a%+'');
} #define max_v 105
int vis[max_v];
int dis[max_v];
int a[max_v];
int G[max_v][max_v];
int cnt[max_v];
int n;
int kk; void init()
{
kk=;
me(a,);
me(vis,);
me(G,);
me(cnt,);
me(dis,);
}
void floyd()
{
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(i==j)
continue;
if(G[i][k]&&G[k][j])
G[i][j]=;
}
}
}
}
int spfa(int s)
{
queue<int> q;
q.push(s);
vis[s]=;
dis[s]=a[s];
cnt[s]++; while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=; for(int i=;i<=n;i++)
{
if(G[u][i]&&dis[i]<dis[u]+a[i])
{
dis[i]=dis[u]+a[i];
if(vis[i]==)
{
q.push(i);
vis[i]=;
cnt[i]++;
if(cnt[i]>n)
{
kk=i;
return ;
}
}
}
}
}
return ;
}
int main()
{
while(~scanf("%d",&n))
{
if(n<)
break;
int x,y,z;
init();
for(int i=;i<=n;i++)
{
scanf("%d %d",&x,&y);
a[i]=x;
while(y--)
{
scanf("%d",&z);
G[i][z]=;
}
}
a[]=;
int flag=spfa();
floyd();
if((flag==&&G[kk][n])||dis[n]>)
{
printf("winnable\n");
}else
{
printf("hopeless\n");
}
}
return ;
}
/*
题目意思:
n个点,每个点有一个权值,存在负权值
构成一个有向图,点从1到n编号,起点是1,终点是n
起点和终点的权值都为0
每个点可以走多次
现在又一个人,从起点开始走,他开始具有100的能量,走到一个点,就加上这个点的权值
如果能量小于等于0的话就会死去,不能到达终点
问你他是否可以到达终点 分析:
每个点可以走多次,意味着只要存在正环且正环上的某个点到n是可达的(所以需要求传递闭包)
那么他一定可以到达n点,这是第一种情况
第二种情况就是跑个最长路,然后dis[n]是大于0的
这两种情况都是可以到达n的 注意最长路dis初始化0...... */

poj 1932 XYZZY(spfa最长路+判断正环+floyd求传递闭包)的更多相关文章

  1. XYZZY spfa 最长路 判环

    题意: 有n个点  m条边  每个边有权值 一开始有一百血  每次经过一条路都会加上其权值 判断是否能够到达n 显然  有正环的时候肯定能够到达 最短路好题!!!!!!! 显用folyed判断是否联通 ...

  2. 【bzoj1179】[Apio2009]Atm Tarjan缩点+Spfa最长路

    题目描述 输入 第一行包含两个整数N.M.N表示路口的个数,M表示道路条数.接下来M行,每行两个整数,这两个整数都在1到N之间,第i+1行的两个整数表示第i条道路的起点和终点的路口编号.接下来N行,每 ...

  3. Currency Exchange POJ - 1860 (spfa判断正环)

    Several currency exchange points are working in our city. Let us suppose that each point specializes ...

  4. Currency Exchange POJ - 1860 spfa判断正环

    //spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...

  5. hdu 1317 XYZZY【Bellheman_ford 判断正环小应用】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1317 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  6. poj1860 兑换货币(bellman ford判断正环)

    传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...

  7. POJ 1932 XYZZY (ZOJ 1935)SPFA+floyd

    http://poj.org/problem?id=1932 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1935 题目大 ...

  8. HDU 6201 2017沈阳网络赛 树形DP或者SPFA最长路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6201 题意:给出一棵树,每个点有一个权值,代表商品的售价,树上每一条边上也有一个权值,代表从这条边经过 ...

  9. poj 1932 XYZZY (最短路径)

    XYZZY Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3105   Accepted: 887 Description ...

随机推荐

  1. python-备忘录模式

    源码地址:https://github.com/weilanhanf/PythonDesignPatterns 说明: 一个成熟的软件应当允许用户取消不确定的操作或者从错误的状态中恢复过来.复制,粘体 ...

  2. (三)MongoDB数据库注意

    1.数据库名 数据库也通过名字来标识.数据库名可以是满足以下条件的任意UTF-8字符串. 不能是空字符串(""). 不得含有' '(空格)...$./.\和\0 (空字符). 应全 ...

  3. Tronado自定义Session

    这里就不一一诉说Session和Cookie直接的关系了,下面以一张图来概括: 下面是一个简单的Tornaod自定义Session的例子,看完后你可能会明白为什么我们在Django里可以直接使用req ...

  4. 清除input numer 点击样式

    input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; }

  5. ionic3 下创建ionic1项目

    一 start命令 ionic start sdscapp --type=ionic1 ——添加平台命令 ionic cordova platform add android

  6. Glusterfs的常用命令

    1 服务器节点 # gluster peer status                          //查看所有节点信息,显示时不包括本节点 # gluster peer probe   N ...

  7. Javascript、Jquery获取浏览器和屏幕各种高度宽度[mark]

    Javascript: IE中:document.body.clientWidth ==> BODY对象宽度document.body.clientHeight ==> BODY对象高度d ...

  8. mybatis-generator 详细配置及使用,爬坑记录

    mybatis-generator 详细配置及使用,爬坑记录 提示:如果不成功一定是项目路径和 数据库配置出问题,本篇基于 MySQL 8.0.13,调试没有问题. 如果失败,建议使用相同的项目结构, ...

  9. 记一次服务器迁移后的nginx启动问题

    背景 服务器A准备下线,故直接将上面的所有应用/资料打包迁移到服务器B.包括搭建的nginx,迁移到B服务器后,楼主偷懒,就想着直接./nginx启动,过程遇到如下问题. ./nginx ./ngin ...

  10. 关于MSCOMM.OCX无法正常注册的问题解决

    [问题] 关于“Component'MSCOMM32.OCX'or one of its dependencies not correctly registered: afole is missing ...