UVA - 10557 XYZZY
来源:互联网 发布:淘宝订单贷款能用多久 编辑:程序博客网 时间:2024/06/05 02:07
题目大意:有 n 个房间,接下来 n 行第一个数字是该房间的能量(可增可减),第二个数字是该房间连通其他房间的个数,后面 k 个数是所连通房间编号。初始能量 100,要求过程中能量都要大于 0,问能否到达终点。
解题思路:
侵删。uva 10557 - XYZZY 关键词:正环,无敌bfs,单源最短路spfa算法 by lzw_java
侵删。SPFA算法详解
没有题解我仿佛是条死鱼……泣
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespace std;bool point[1000][1000], vis[1000];int value[1000], energy[1000], q[10000000];int n;bool spfa() { int t1, t2; t1 = t2 = 0; vis[0] = true; energy[0] = 100; q[t2++] = 0; int cnt = 0; while (t1 != t2) { int t = q[t1++]; for (int i = 0; i < n; i++) if (point[t][i] && energy[i] < energy[t] + value[i]) { energy[i] = energy[t] + value[i]; if (!vis[i]) { q[t2++] = i; vis[i] = true; cnt++; } } if (energy[n-1] > 0) return true; else if (cnt > 1000000) return false; vis[t] = false; } return false;}int main() { while (scanf("%d", &n) != EOF && n != -1) { memset(point, false, sizeof(point)); memset(energy, 0, sizeof(value)); memset(vis, false, sizeof(vis)); int k; for (int i = 0; i < n; i++) { scanf("%d%d", &value[i], &k); for (int j = 0; j < k; j++) { int t; scanf("%d", &t); point[i][t-1] = true; } } int tag = spfa(); if (tag) printf("winnable\n"); else printf("hopeless\n"); }return 0;}
0 0
- UVa 10557 - XYZZY
- uva 10557 - XYZZY
- UVA 10557 XYZZY
- uva 10557 - XYZZY
- UVA 10557 XYZZY
- UVA 10557 XYZZY
- UVA - 10557 XYZZY
- UVA 10557 - XYZZY
- XYZZY - UVa 10557 图论
- UVA 10557 XYZZY
- UVa 10557 - XYZZY
- UVA 10557 XYZZY
- Uva 10557 XYZZY
- UVA 10557-XYZZY
- UVA - 10557 XYZZY
- uva 10557 - XYZZY hdu 1317
- UVa 10557 & HDU 1317 - XYZZY
- uva 10557 XYZZY(DFS+BFS)
- [知了开发]“知了”优化 - WebMagic 调优
- 最详细的SVN安装使用手册-Centos6.4系统运行通过
- KCon黑客大会十大神器webzmap的安装与使用
- poj1979【基础bfs/dfs】
- Python 之 WSGI
- UVA - 10557 XYZZY
- Python-产生随机数
- 使用POSIX Threads进行多线程编程(三) ——条件变量
- 混合开发(一)——WebView开发高级技巧之加载网页以及JavaScript,加载进度条
- UVA - 10004 Bicoloring
- |Tyvj|并查集|P1602 团伙
- [BZOJ4523] [CQOI2016] 路由表 - Trie - 单调栈
- C#窗体控件随窗体变大而变大
- 链栈 - 栈的链式存储