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],问最小花费可 ...
随机推荐
- python自动华 (十六)
Python自动化 [第十六篇]:JavaScript作用域和Dom收尾 本节内容: javascript作用域 DOM收尾 JavaScript作用域 JavaScript的作用域一直以来是前端开发 ...
- IDEA创建类似于Eclipse的source folder
1.新建普通文件夹目录directory 2.当前Module右键Open Mudule Settings(F12) 3.选中新建的文件夹并单击上面的Sources,看到文件夹颜色变化即成功.
- 016_STM32程序移植之_舵机
STM32程序移植之舵机PWM测试 接线图如下: STM32引脚 舵机引脚 功能 GND GND 正极电源 具体看舵机的额定电压 PA6 PWM引脚 STM32引脚 CH340引脚 GND GND 3 ...
- CF 940F - Machine Learning ( 带 修 )
题目: 链接:https://codeforces.com/problemset/problem/940/F 题意:给你n个数,a[i]有q个操作,操作有两种:操作1. 1 x y 表示询 ...
- MySQL数据分析-(5)数据库设计之ER模型
大家好,我是jacky,很高兴跟大家分享本课时的内容,从本节课开始,就开始了我们第二章的学习,第一章我们抛出了若干问题,从第二章开始往后,都是解决问题的一个过程: 第一章的案例中,我们拿手机销售公司举 ...
- keras 模型简介
keras模型在keras中主要有两种模型,顺序模型,以及模型类(类的内部有函数) model.layers 是层的列表,他们组成了模型 model.inputs 是模型输入的张量 model.out ...
- 爬虫之操作excel
几种常用模块的使用方法 注释:Excel 2003 即XLS文件有大小限制即65536行256列,所以不支持大文件,而Excel 2007以上即XLSX文件的限制则为1048576行16384列 下面 ...
- 使用Excel拼凑SQL语句
快速将一列多行数据合并到一个单元格 EXCEL如何快速将一列多行数据合并到一个单元格,并加分隔符?这是批量处理由一线业务员统计的数据时的常用方法,尤其是当一列数据是wher ...
- android中的Section ListView
前几天,和ios开发的同事扯淡时发现iphone里有个section listview,分章节的列表.android中的联系人也有这种效果,首字母相同的联系人会被分在一个章节中. 后来搜了一下,and ...
- docker运行puppeteer出现Page crash解决方案
Docker默认文件空间64MB.如果puppeteer运行的时候超过这个内存就出现了.Page crash.可以使用docker run --shm-size=256m指定一个更大的内存即可.