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. 【 js 基础 】为什么 call 比 apply 快?

    这是一个非常有意思的问题. 在看源码的过程中,总会遇到这样的写法: var triggerEvents = function(events, args) { var ev, i = -1, l = e ...

  2. nginx禁止ip默认参数是$remote_addr无法禁止真实ip的问题

    由于网站使用了cdn所以$remote_addr获取的ip是cdn的ip,我现在先禁止某些ip访问发现无法禁止cdn传递过来的客户端的ip也就是$http_x_forwarded_for这个参数.比如 ...

  3. Android 优秀开源项目

    以下是本人日常工作中收集的比较不错的Android开源项目 roottools: RootTools gives Rooted developers easy access to common roo ...

  4. [WPF 基础知识系列] —— 绑定中的数据校验Vaildation

    前言: 只要是有表单存在,那么就有可能有对数据的校验需求.如:判断是否为整数.判断电子邮件格式等等. WPF采用一种全新的方式 - Binding,来实现前台显示与后台数据进行交互,当然数据校验方式也 ...

  5. go语言练习:条件语句和循环语句

    1.for循环+if条件语句简单例子: package main import "fmt" func main() { var a int for a = 0; a <= 2 ...

  6. Git删除文件

    Git基础 Git有三大区(工作区.暂存区.版本库),文件有三个状态(untracked.unstaged.uncommited). (1)打开项目文件夹,除了隐藏的.git文件夹,其他项目文件位于的 ...

  7. 2018-02-03-PY3下经典数据集iris的机器学习算法举例-零基础

    ---layout: posttitle: 2018-02-03-PY3下经典数据集iris的机器学习算法举例-零基础key: 20180203tags: 机器学习 ML IRIS python3mo ...

  8. Hibernate中对象的三种状态及相互转化

    1. 瞬时状态 (Transient) 当我们通过Java的new关键字来生成一个实体对象时,这时这个实体对象就处于自由状态,如下:  Customer customer=new Customer(“ ...

  9. eclipse中svn插件的工程不能与svn资源库同步的解决方法

    eclipse中svn插件的工程不能与svn资源库同步的解决办法 最近几天自己的工程与资源库同步总是出现问题,重启机器后发现资源库丢失了,无法进行同步. 解决办法如下: 1.右键工程---->选 ...

  10. oracle中insert 多条数据方法

    oracle中的insert 和 mysql添加多条数据的 方式不太一样 用到的语法: insert all into 表名(需要添加的表字段)values(添加的字段数据一定要对应字段顺序) int ...