uva 10557 - XYZZY (最长路)

本文深入探讨了经典的计算机冒险游戏及其发展历程,包括其规则、玩法及如何在现代设备上运行开源软件。通过分析游戏机制,揭示了如何通过SPFA算法解决最长路径问题,并提供了实现该算法的代码实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

G. V. Cormack

用spfa求最长路。因为可能有正圈,所以对于这种情况要特别判断。如果这个圈可以到 n ,则win。所以可以反向建图,从n出发搜索可以到达的点。

#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<string>
#include<set>
#include<map>
using namespace std;
const int maxn = 100 + 5;
const int mod = 1000000000 + 7;
const double eps = 1e-7;
const int INF = 1000000000;
typedef long long LL;
typedef pair<LL, int> P;

vector<int> G[maxn], rG[maxn];
int val[maxn];
int n;
int can[maxn];

void dfs(int x){
    can[x] = 1;
    for(int i = 0;i < rG[x].size();i++){
        int to = rG[x][i];
        if(!can[to])
            dfs(to);
    }
}

LL dis[maxn], cnt[maxn];
priority_queue<P> pq;

bool bfs(){
    while(!pq.empty())
        pq.pop();
    pq.push(P(100, 1));
    memset(dis, 0, sizeof dis);
    memset(cnt, 0, sizeof cnt);
    dis[1] = 100;
    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        LL eng = p.first;
        int pos = p.second;
        if(eng < dis[pos])
            continue;
        if(cnt[pos] > n || pos == n){
            return true;
        }

        for(int i = 0;i < G[pos].size();i++){
            int to = G[pos][i];
            if(can[to] && dis[pos]+val[to] > dis[to]){
                dis[to] = dis[pos]+val[to];
                pq.push(P(dis[to], to));
                cnt[to]++;
            }
        }
    }
    return false;
}

int main(){
    while(scanf("%d", &n)){
        if(n == -1)
            break;
        for(int i = 0;i < maxn;i++){
            G[i].clear();
            rG[i].clear();
        }
        for(int i = 1;i <= n;i++){
            int num;
            scanf("%d%d", &val[i], &num);
            while(num--){
                int x;
                scanf("%d", &x);
                G[i].push_back(x);
                rG[x].push_back(i);
            }
        }
        memset(can, 0, sizeof can);
        dfs(n);

        if(bfs())
            printf("winnable\n");
        else
            printf("hopeless\n");

    }
    return 0;
}
/*
7
0 1 2
0 2 3 5
-100 1 4
-100 1 7
1 1 6
0 1 5
0 0

5
0 1 4
100 1 5
-80 1 2
-90 1 3
0 0

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
7
0 1 2
-98 2 3 5
-1 1 4
101 1 1
-60 1 6
-60 1 7
0 0
8
0 1 2
0 1 3
-5 1 4
-50 1 5
-40 2 6 7
110 1 3
0 1 8
0 0
1
0 0

7
0 2 2 6
-60 1 3
100 1 4
100 1 5
100 1 2
-120 1 7
0 0

15
0 2 2 11
-10 1 3
-10 1 4
-10 1 5
-10 1 6
-10 1 7
-10 1 8
-10 1 9
-10 1 10
-10 1 13
50 1 12
50 1 11
11 2 10 14
-100 1 15
0 0


*/


资源下载链接为: https://pan.quark.cn/s/3d8e22c21839 随着 Web UI 框架(如 EasyUI、JqueryUI、Ext、DWZ 等)的不断发展与成熟,系统界面的统一化设计逐渐成为可能,同时代码生成器也能够生成符合统一规范的界面。在这种背景下,“代码生成 + 手工合并”的半智能开发模式正逐渐成为新的开发趋势。通过代码生成器,单表数据模型以及一对多数据模型的增删改查功能可以被直接生成并投入使用,这能够有效节省大约 80% 的开发工作量,从而显著提升开发效率。 JEECG(J2EE Code Generation)是一款基于代码生成器的智能开发平台。它引领了一种全新的开发模式,即从在线编码(Online Coding)到代码生成器生成代码,再到手工合并(Merge)的智能开发流程。该平台能够帮助开发者解决 Java 项目中大约 90% 的重复性工作,让开发者可以将更多的精力集中在业务逻辑的实现上。它不仅能够快速提高开发效率,帮助公司节省大量的人力成本,同时也保持了开发的灵活性。 JEECG 的核心宗旨是:对于简单的功能,可以通过在线编码配置来实现;对于复杂的功能,则利用代码生成器生成代码后,再进行手工合并;对于复杂的流程业务,采用表单自定义的方式进行处理,而业务流程则通过工作流来实现,并且可以扩展出任务接口,供开发者编写具体的业务逻辑。通过这种方式,JEECG 实现了流程任务节点和任务接口的灵活配置,既保证了开发的高效性,又兼顾了项目的灵活性和可扩展性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值