POJ 3621 (最优比率环 二分+SPFA)
来源:互联网 发布:linux 发送at指令 编辑:程序博客网 时间:2024/05/02 01:08
题目链接:点击这里
题意:找出一个环, 最大化
假设答案是ans.那么有
#include <cstdio>#include <iostream>#include <cstring>#include <queue>#include <cmath>#include <algorithm>#define Clear(x,y) memset (x,y,sizeof(x))#define FOR(a,b,c) for (int a = b; a <= c; a++)#define REP(a,b,c) for (int a = b; a >= c; a--)#define fi first#define se second#define pii pair<int, int>#define pli pair<long long, int>#define pb push_back#define mod 1000000007using namespace std;#define maxn 1005#define maxm 5005int n, m;int val[maxn];struct node { int u, v, num, next; double w;}edge[maxm];int head[maxn], cnt;void add_edge (int u, int v, int w) { edge[cnt].num = w; edge[cnt].u = u, edge[cnt].v = v, edge[cnt].next = head[u], head[u] = cnt++;}bool vis[maxn];int top, num[maxn];double d[maxn];bool spfa (double ans) { queue <int> q; while (!q.empty ()) q.pop (); for (int i = 1; i <= n; i++) { vis[i] = 1; d[i] = 0; q.push (i); num[i] = 1; } for (int i = 0; i < cnt; i++) { node &e = edge[i]; e.w = (val[e.u]+val[e.v])/2.0-ans*e.num; } while (!q.empty ()) { int u = q.front (); q.pop (); vis[u] = 0; for (int i = head[u]; i+1; i = edge[i].next) { int v = edge[i].v; if (d[v] < d[u]+edge[i].w) { d[v] = d[u]+edge[i].w; if (!vis[v]) { vis[v] = 1; q.push (v); if (++num[v] > n) return 1; } } } } return 0;}int main () { //freopen ("more.in", "r", stdin); while (scanf ("%d%d", &n, &m) == 2) { double l = 0, r = 0; for (int i = 1; i <= n; i++) { scanf ("%d", &val[i]); r += val[i]; } Clear (head, -1); cnt = 0; for (int i = 1; i <= m; i++) { int u, v, w; scanf ("%d%d%d", &u, &v, &w); add_edge (u, v, w); } while (r-l > 1e-5) { double mid = (l+r)/2; if (spfa (mid)) l = mid; else r = mid; } printf ("%.2f\n", l); } return 0;}
0 0
- POJ 3621 (最优比率环 二分+SPFA)
- POJ 3621 最优比率生成环 二分求解
- poj 3621(最优比率环)
- POJ 3621 最优比率环
- POJ 3621 最优比率生成环
- POJ 3621 Sightseeing Cows 最优比率环
- POJ 3621 Sightseeing Cows 最优比率环
- poj 3621 最优比率圈
- bzoj1690 [Usaco2007 Dec]奶牛的旅行(最优比率环,二分答案+spfa判负环)
- POJ 3621 最优比率生成环 01分数规划问题
- poj 3621 Sightseeing Cows(最优比率环)
- poj 3621 Sightseeing Cows (最优比率环)
- POJ-3621: Sightseeing Cows【最优比率生成环】
- POJ 2728 Desert King(最优比率生成树) prim+二分
- POJ 2728 (最优比率生成树+二分或者迭代)
- poj 3621 二分+spfa
- poj 3621 Sightseeing Cows (最优比率生成环 01分数规划问题 )
- POJ 3621 Sightseeing Cows(最优比率环/01分数规划)
- 执行yum安装出错的解决办法
- 2125: 最短路
- mybatis核心配置文件mybatis-config.xml的配置方法和配置详情
- jquery EasyUI datagrid重新加载传参问题
- Web.config配置详解
- POJ 3621 (最优比率环 二分+SPFA)
- C++ 中重载与覆盖
- 机器学习——武林盟主分享机器学习之武功秘籍
- js数组排序 reverse()和sort()方法的使用 复制数组slice()和克隆数组concat()
- nice validator校验总结
- SSH账户更新不成功
- easyui设置pagesize后台没法接受
- 大和
- caffe 上OpenBLAS的安装使用