码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • H - XYZZY(spfa最大路径,判断正环)


    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

    InputcopyOutputcopy
     
    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 
     
    hopeless hopeless winnable winnable
    1. #include <iostream>
    2. #include <vector>
    3. #include <utility>
    4. #include <cstring>
    5. #include <queue>
    6. using namespace std;
    7. int n,nl[105],dist[105],cnt[105];
    8. vector<int>adj[105];
    9. bool st[105];
    10. int spfa(){
    11. memset(dist,0,sizeof(dist));
    12. memset(cnt,0,sizeof(cnt));
    13. memset(st,0,sizeof(st));
    14. dist[1]=100;
    15. queue<int>q;
    16. q.push(1);
    17. while(!q.empty()){
    18. int t=q.front();
    19. q.pop();
    20. if(cnt[t]>=n+1) continue;
    21. st[t]=0;
    22. cnt[t]++;
    23. if(cnt[t]==n+1) dist[t] = 1000000;
    24. for(auto it:adj[t]){
    25. if(dist[it]<dist[t]+nl[it]&&dist[t]+nl[it]>0){
    26. if(it==n) return 1;
    27. dist[it]=dist[t]+nl[it];
    28. if(!st[it])
    29. q.push(it);
    30. st[it]=1;
    31. }
    32. }
    33. }
    34. return false;
    35. }
    36. int main() {
    37. while (cin >> n&&n!=-1) {
    38. for (int i = 1; i <= n; i++) {
    39. adj[i].clear();
    40. }
    41. for (int i = 1; i <= n; i++) {
    42. scanf("%d", &nl[i]);
    43. int temp;
    44. scanf("%d", &temp);
    45. while (temp--) {
    46. int v;
    47. scanf("%d",&v);
    48. adj[i].push_back(v);
    49. }
    50. }
    51. if(spfa()) printf("winnable\n");
    52. else printf("hopeless\n");
    53. }
    54. }

     

  • 相关阅读:
    0701~放假总结
    2022深圳杯C题自动驾驶电动物料车换电站选址及调度方案
    【达内shell脚本实战案例】一个funexpr.sh脚本:由用户在执行时提供2个整数值参数,计算这2个整数的加、减、乘、除结果
    近期为何事故频发,企业安全生产如何保障?
    CSDN流量卷领取和使用保姆级教程——流量卷,恭喜获得每日任务奖励【1500曝光】可获得新增曝光,阅读转化,点赞转化,新增关注-流量卷,流量卷,流量卷
    extern 和 extern “C“
    一款功能强大的Python工具,一键打包神器,一次编写、多平台运行!
    ssm中项目异常处理
    Centos7的系统管理(systemctl、系统运行级别、关机)
    NewStarCTF2023week2-R!!C!!E!!
  • 原文地址:https://blog.csdn.net/q619718/article/details/128007324
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号