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

最新文章

  1. [DPDK][转]DPDK编程开发(4)—lcore
  2. [转载]Matlab之静态文本多行输出
  3. Javascript起源...
  4. matlab文件操作及读txt文件(fopen,fseek,fread,fclose)
  5. avatar Logo
  6. LA 2038
  7. mac 生成支付宝的rsa公钥和私钥 php版本
  8. eclise -The method onClick(View) of type new View.OnClickListener(){} must override a superclass method
  9. 【HDOJ】1403 Longest Common Substring
  10. 用fcntl()设置堵塞函数的堵塞性质
  11. 石头剪刀布 R语言统计分析
  12. Vivado常见问题集锦
  13. SmartSql Map
  14. create-react-app 修改项目端口号及ip,设置代理
  15. c++算法实现(一) - 递归和初始化
  16. 【BZOJ5417】[NOI2018]你的名字(线段树,后缀自动机)
  17. 潭州课堂25班:Ph201805201 django 项目 第十五课 用户注册功能后台实现 (课堂笔记)
  18. 一张图知道HTML5布局(图)
  19. 使用VNC连接管理VPS
  20. 2.Linux环境下配置Solr4.10.3

热门文章

  1. Python标准库--UUID
  2. 【机器学习】EM算法详细推导和讲解
  3. PDO异常处理
  4. 【代码笔记】iOS-MBProgressHUD+MJ
  5. web界面 之 登录 (初稿)
  6. zigzag方式编码
  7. JDK7下VisualVm插件无法链接到插件中心
  8. Django 序列化三种方式 对象 列表 元组
  9. Java:基本数据类型与类型转换
  10. idea总是编译启动报错