POJ3621 Sightseeing Cows
来源:互联网 发布:tumblr类似软件 编辑:程序博客网 时间:2024/05/17 04:22
又被G++坑了一次。。。。。算了不提也罢。
题意要找一个环游路线使得 收益/花费 最大,显然是基环,于是分数规划,判断是否有正权圈。
然后
弃疗
发现好像不会求正权圈唉。
算了,取反。
改求负权圈,spfa一下就好了。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<cmath>using namespace std;const int N=1000+5;const double eps=1e-6;struct Edge{int to,next;double w,c;}e[N*10];int head[N],cnt;void ins(int u,int v,double w){e[++cnt]=(Edge){v,head[u],w,0};head[u]=cnt;}int in[N];bool inq[N];int n,m;double d[N];bool spfa(){queue<int>q;for(int i=1;i<=n;i++){d[i]=0;in[i]=0;inq[i]=1;q.push(i);}while(!q.empty()){int u=q.front();q.pop();inq[u]=false;for(int i=head[u];i;i=e[i].next){int v=e[i].to;if(d[v]>d[u]+e[i].c){d[v]=d[u]+e[i].c;if(!inq[v]){if(++in[v]==n)return true;inq[v]=true;q.push(v);}}}}return false;}int dcmp(double x){if(fabs(x)<eps)return 0;return x<0?-1:1;}double f[N];void build(double x){for(int i=1;i<=cnt;i++)e[i].c=-(f[e[i].to]-x*e[i].w);}int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)scanf("%lf",&f[i]);int u,v;double w;for(int i=1;i<=m;i++){scanf("%d%d%lf",&u,&v,&w);ins(u,v,w);}double l=0,r=20000;while(r-l>eps){double mid=(l+r)/2;build(mid);if(spfa())l=mid;else r=mid;}if(!dcmp(l))putchar('0');else printf("%.2f",l);return 0;}
0 0
- poj3621 Sightseeing Cows
- POJ3621 Sightseeing Cows
- POJ3621 Sightseeing Cows
- POJ3621 Sightseeing Cows
- poj3621 Sightseeing Cows
- [POJ3621] Sightseeing Cows
- poj3621 Sightseeing Cows bellman-ford 判负权环
- poj3621 Sightseeing Cows --- 01分数规划
- POJ3621 Sightseeing Cows(最优比率环)
- [POJ3621]Sightseeing Cows(01分数规划)
- POJ3621 Sightseeing Cows 分数规划 SPFA求最小环
- POJ3621 sightseeing cows 01分数规划+SPFA判定
- poj3621 Sightseeing Cows 【最大比例环 01分数规划】
- poj3621:Sightseeing Cows(0/1分数规划、SPFA判负环)
- POJ3621 Sightseeing Cows 最短路求最优比率生成环
- 【分数规划-最大比例环】POJ3621[Sightseeing Cows]题解
- 【分数规划】【最优比率环 & 最优比率生成树】poj3621 Sightseeing Cows && poj2728 Desert King
- POJ 3621 Sightseeing Cows
- fatal: Not a git repository (or any of the parent directories): .git
- stm32库函数学习篇---NVIC与外部中断
- Makefile学习
- 25 不使用加减乘除做加法
- 10个重要的Linux ps命令实战
- POJ3621 Sightseeing Cows
- 程序设计常用的C++模板库(STL)
- VACCUM
- java 生成一组不重复的随机数
- python实现找到第i小的元素
- Java 中4种访问修饰符 public/protected/default(friendly)/private
- Java 基础之CallBack的使用
- HDU 1081 最大子矩阵(LCS_DP+前缀和)
- web前端小经验