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 ...
随机推荐
- Goolg Chrome 插件开发--Hello world
开发Chrome插件很简单,只要会web开发(html+javascript+css)那么这个就是能驾轻就熟,只需要了解一下插件具体的运行环境及要求就OK了. 1.先创建一个html文件,名字随便取, ...
- Sqli-labs less 42
Less-42 Update更新数据后,经过mysql_real_escape_string()处理后的数据,存入到数据库当中后不会发生变化.在select调用的时候才能发挥作用.所以不用考虑在更新密 ...
- C#中的可空类型
public class Person { public DateTime birth; public DateTime? death; string name; public TimeSpan Ag ...
- hdu 2413(最大匹配+二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...
- C# winform post请求数据
刚到公司混的时候,老板要求实现一个从C#的windows应用程序传参数到一个网页,然后这个网页不显示出来,但能把数据返回给应用程序的功能,问了好多人,找了好多资料,都搞不定,后来还是在老板的帮助下搞定 ...
- 4 tips for staying productive on Friday
4 tips for staying productive on Friday如何让你的周五和周一一样有效率1.Schedule Your Day with Tasks 用任务计划一天 Sometim ...
- SIM卡
SIM卡是(Subscriber Identity Module 客户识别模块)的缩写 也称为用户身份识别卡.智能卡,GSM数字移动电话机必须装上此卡方能使用.在电脑芯片上存储了数字移动电话客户的信息 ...
- 307. Range Sum Query - Mutable
题目: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclu ...
- java string,需要进行首字母大写改写
java string,需要进行首字母大写改写,网上大家的思路基本一致,就是将首字母截取,转化成大写然后再串上后面的,类似如下代码 //首字母大写 public static String c ...
- [c/c++]指针数组 pk 数组指针
首先强调 指针数组归根结底是个数组:数组指针归根结底是个指针. 数组指针 以int (*int)[10]为例 ()的优先级大于[],因此首先它是一个指针,它指向一个数组,数组的维数是10.因此数组指针 ...