HDU 1317 XYZZY【Bellman_Ford判断正环】
题意:给出n个房间,初始在房间1有100的能量值,每次进入一个房间,能量值可能增加也可能减小,(是点权,不是边权),问能否到达终点的时候能量值还为正
这题自己写的时候wa--wa--
后来看了题解,还是wa---wa---
题解很详细http://blog.csdn.net/freezhanacmore/article/details/9937327
记录下自己犯的错误吧
首先是floyd函数初始化的时候,直接写在了函数里面,这样是不对的,因为输入值在前,调用函数在后,这样就相当于将之前输入的可能部分改变了(这个改了好久啊-----55555)
还有就是Bellman_ford时,因为是求正环,所以是d[i][j]=-INF(i!=j)
还有就是输入的权值是点权
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = ;
const int mod=;
const int maxn=;
int en[maxn],d[maxn],w[maxn][maxn];
int n,m,ecnt; struct Edge{
int u,v;
} e[maxn*maxn]; void add(int u,int v){
e[++ecnt].u=u;
e[ecnt].v=v;
} void floyd(){
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
w[i][j]=w[i][j]||(w[i][k]&&w[k][j]);
} int Bellman_ford(){
for(int i=;i<=n;i++) d[i]=-INF;
d[]=; for(int i=;i<n;i++){
for(int j=;j<=ecnt;j++){
int v=e[j].v;
int u=e[j].u;
if(d[v]<d[u]+en[v]&&d[u]+en[v]>){
d[v]=d[u]+en[v];
}
}
} for(int j=;j<=ecnt;j++){
int v=e[j].v;
int u=e[j].u;
if((d[v]<d[u]+en[v])&&d[u]+en[v]>) {
if(w[v][n])
return ;
}
}
return d[n]>;
} int main(){
int num;
while(scanf("%d",&n)!=EOF&&n!=-){
ecnt=; memset(en,,sizeof(en));
memset(w,,sizeof(w));
for(int i=;i<=n;i++) w[i][i]=;
for(int i=;i<=n;i++){
scanf("%d %d",&en[i],&num);
while(num--){
int u;
scanf("%d",&u);
w[i][u]=;
add(i,u);
}
} floyd();
if(Bellman_ford()) printf("winnable\n");
else printf("hopeless\n");
}
return ;
}
加油啊- go---go--go
HDU 1317 XYZZY【Bellman_Ford判断正环】的更多相关文章
- poj 1860 (Bellman_Ford判断正环)
题意:给出n种货币,m中交换关系,给出两种货币汇率和手续费,求能不能通过货币间的兑换使财富增加. 用Bellman_Ford 求出是否有正环,如果有的话就可以无限水松弛,财富可以无限增加. #incl ...
- 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.初始 ...
- poj - 1860 Currency Exchange Bellman-Ford 判断正环
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...
- [HDU 1317]XYZZY[SPFA变形][最长路]
题意: 一个图, 点权代表走到该点可获得的能量值. 可正可负. 一个人从1 号出发,带有100点能量. 问是否有一种方案可使人在能量值>0的时候走到n. 思路: 这个题首先要注意点权. 其实就是 ...
- Currency Exchange POJ - 1860 (spfa判断正环)
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- poj1860 兑换货币(bellman ford判断正环)
传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...
- Currency Exchange POJ - 1860 spfa判断正环
//spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...
- HDU 1317(Floyd判断连通性+spfa判断正环)
XYZZY Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
随机推荐
- SGU 113
113. Nearly prime numbers time limit per test: 0.25 sec. memory limit per test: 4096 KB Nearly prime ...
- POJ 1317
#include <iostream> #include <string> using namespace std; char p_code[] = {'_','a','b', ...
- ExtJs之Ext.getCmp
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- intelli IDEA node开发代码提示问题
好几天没写代码了,今天新建一个项目,在引入rs这个文件系统模块时却没有关于这个模块的代码提示,着实令人恶心啊.还好最终解决了. 在没有代码提示的时候点击如下图标: 出现如下的界面,其中有个Edit u ...
- Tomcat目录结构
首先来了解一下Tomcat5.5的目录结构: /bin:存放windows或Linux平台上启动和关闭Tomcat的脚本文件 /conf:存放Tomcat服务器的各种全局配置文件,其中包括server ...
- 简单验证码识别 tessnet2
今天突然间对识别验证码感兴趣,于是网上搜了一下 最简单的是引用tessnet2.dll,然后通过它来识别,代码如下 private void button1_Click(object sender, ...
- 网络打洞(P2P软件穿透内网进行通信) 原理
http://www.cnblogs.com/gansc23/archive/2010/10/20/1857066.html 首先先介绍一些基本概念:NAT(Network Address Trans ...
- SIM卡
SIM卡是(Subscriber Identity Module 客户识别模块)的缩写 也称为用户身份识别卡.智能卡,GSM数字移动电话机必须装上此卡方能使用.在电脑芯片上存储了数字移动电话客户的信息 ...
- CreateFile,WriteFile,ReadFile
注意: CreateFile 跟 fopen 不同,打开文件时不区分 文本方式 或 二进制 方式 ReadFile 或 WriteFile 都是对二进制数据进行操作 HANDLE WINAPI Cre ...
- 通用sqlserver分页存储过程
来自:http://www.cnblogs.com/vagerent/archive/2007/10/17/927825.html 单主键: CREATE PROC P_viewPage /** ...