HDU 1317:XYZZY
Problem Description 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 rooms. One of the rooms is the start and one of the rooms is the finish. Each room has an energy value between - and +. One-way doorways interconnect pairs of rooms. The player begins in the start room with 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 (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 . A line containing - 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 -
- -
- -
- -
- - Sample Output hopeless
hopeless
winnable
winnable
题目
题目大意:一个最多有100个节点的图,你需要从1走到n(注意哦,有向边)。初始有100个能量,到达一个点会使你的能量值变化,如果能在能量为正的情况下到达点n则输出“NOIP有希望了dalao%%%”,否则输出“NOIP翻车了好开心”。(233333~)
芒果君:之前我们做的都是最短路,现在要做最长路,改个符号就行了。这道题对于我的难点是——如何判环。在不断更新最长路时负环可以忽略,但遇到正环应该怎样处理?我看到有一种Floyd+SPFA的方法比较好理解,其实很像广搜。这道题数据比较小,那我们就先做一遍Floyd,在SPFA中记录一个点被放进队列的次数,如果这个次数很不科学(cnt==n),那么就说明它在正环里。But,存在正环不能说明到不了终点,相反,如果它与终点连通,一定能到达(如果你觉得正环到终点可能能量会耗尽,那么请你讲正环看成无敌聚能环233333再好好想想),所以我们要在之前处理连通性。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<vector>
using namespace std;
vector<int>e[];
queue<int>Q;
int oc[],vis[],dis[],map[][],n,w[];
int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>''){
if(ch=='-') f=-;
ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
void floyd()
{
for(int k=;k<=n;++k)
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
map[i][j]=map[i][j]||(map[i][k]&&map[k][j]);
}
bool spfa()
{
memset(dis,-/,sizeof(dis));
memset(vis,,sizeof(vis));
memset(oc,,sizeof(oc));
dis[]=;
Q.push();
vis[]=;
oc[]=;
while(!Q.empty()){
int x=Q.front();
Q.pop();
vis[x]=;
if(oc[x]>=n) {
if(map[x][n]) return true;
else continue;
}
for(int i=;i<e[x].size();++i){
int v=e[x][i];
if(dis[v]<dis[x]+w[v]&&dis[x]+w[v]>){
dis[v]=dis[x]+w[v];
if(v==n) return true;
if(!vis[v]){
oc[v]++;
vis[v]=;
Q.push(v);
}
}
}
}
return false;
}
int main()
{
int cnt,t;
while(){
scanf("%d",&n);
if(n==-) break;
memset(map,,sizeof(map));
for(int i=;i<=n;++i){
e[i].clear();
w[i]=read();cnt=read();
while(cnt--){
t=read();
e[i].push_back(t);
map[i][t]=;
}
}
floyd();
if(spfa()) printf("winnable\n");
else printf("hopeless\n");
}
return ;
}
HDU 1317:XYZZY的更多相关文章
- HDU - 6409:没有兄弟的舞会(数学+思维)
链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- hdu 1317 XYZZY【Bellheman_ford 判断正环小应用】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1317 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1317 XYZZY(floyd+bellman_ford判环)
http://acm.hdu.edu.cn/showproblem.php?pid=1317 题意: 给出一个有向图,每到达一个点,都会加上或减去一些能量,我们要做的就是判断从1出发是否能到达n.初始 ...
- hdu 1317 XYZZY
http://acm.hdu.edu.cn/showproblem.php?pid=1317 #include <cstdio> #include <queue> #inclu ...
- HDU 1317 XYZZY【Bellman_Ford判断正环】
题意:给出n个房间,初始在房间1有100的能量值,每次进入一个房间,能量值可能增加也可能减小,(是点权,不是边权),问能否到达终点的时候能量值还为正 这题自己写的时候wa--wa-- 后来看了题解,还 ...
- [HDU 1317]XYZZY[SPFA变形][最长路]
题意: 一个图, 点权代表走到该点可获得的能量值. 可正可负. 一个人从1 号出发,带有100点能量. 问是否有一种方案可使人在能量值>0的时候走到n. 思路: 这个题首先要注意点权. 其实就是 ...
- HDU 2732:Leapin' Lizards(最大流)
http://acm.hdu.edu.cn/showproblem.php?pid=2732 题意:给出两个地图,蜥蜴从一个柱子跳跃到另外一个地方,那么这个柱子就可能会坍塌,第一个地图是柱子可以容忍跳 ...
- HDU 4289:Control(最小割)
http://acm.hdu.edu.cn/showproblem.php?pid=4289 题意:有n个城市,m条无向边,小偷要从s点开始逃到d点,在每个城市安放监控的花费是sa[i],问最小花费可 ...
随机推荐
- 14、Spring Boot 2.x 集成 Druid 数据源
14.Spring Boot 2.x 集成 Druid 数据源 完整源码: Spring-Boot-Demos
- Win10远程桌面 报错:CredSSP加密Oracle修正……
解决方法: 运行 gpedit.msc 本地组策略: 计算机配置>管理模板>系统>凭据分配>加密Oracle修正 选择启用并选择易受攻击. 参考: https://blog.c ...
- ES6-12.Symbol
Symbol是ES6新增的原始类型数据,引入的初衷是为了对象可以有永不重复的属性名. 所以属性名可以是字符串外,还可以是Symbol值: const a = Symbol("a") ...
- The method setCharacterEncoding(String) is undefined for the type HttpServletResponse
今天将以前做的一个web项目从不笔记本上移到台式机上,import项目后出现“The method setCharacterEncoding(String) is undefined for the ...
- Gym - 102307D Do Not Try This Problem
Do Not Try This Problem Gym - 102307D 题意:给个长度为len的字符串(len<=1e5),然后q次操作(q<=1e5),每次给出i,a,k,c,(i ...
- sqlserver 存储过程的新建与执行
if Exists(select * from sysobjects where NAME = 'insert_custominfo' and type='P') drop procedure ins ...
- WebService基础学习
参考 WebService基础学习(一)—基础知识:http://www.cnblogs.com/yangang2013/p/5708647.html WebService基础学习(二)—三要素:ht ...
- 学习ArrayList的扩容机制
基于jdk8 1.首先我们看new ArrayList中 public ArrayList() { this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDA ...
- YouTube 网站的架构演进——阅读心得
基础平台 Apache Python Linux(SuSe) MySQL psyco,一个动态的Python到C的编译器 lighttpd代替Apache做视频播放 状态 支持每天超过5亿的视频点击量 ...
- The first one spawns an additional process forwarding requests to a series of workers (think about it as a form of shield, at the same level of apache or nginx), while the second one sets workers to n
Things to know (best practices and “issues”) READ IT !!! — uWSGI 2.0 documentationhttps://uwsgi-docs ...