[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=5367

[算法]

很明显的分数规划问题

预处理从一个点走到另一个点所获最大利润和最短路

SPFA判正环是否存在即可

时间复杂度 : O(N ^ 2K + N ^ 2 logN)

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define N 1010
#define M 10010
const double inf = 1e15;
const double EPS = 1e-; int n , m , k;
int cnt[N];
ll dist[N][N] , cst[N][N] , B[N][N] , S[N][N];
double D[N][N] , dis[N];
bool inq[N]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline bool check(double mid)
{
queue< int > q;
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
D[i][j] = 1.0 * cst[i][j] - 1.0 * dist[i][j] * mid;
}
}
memset(inq , false , sizeof(inq));
for (int i = ; i <= n; i++)
{
q.push(i);
inq[i] = true;
cnt[i] = ;
dis[i] = -inf;
}
while (!q.empty())
{
int cur = q.front();
q.pop();
inq[cur] = false;
for (int i = ; i <= n; i++)
{
if (dis[cur] + D[cur][i] >= dis[i])
{
dis[i] = dis[cur] + D[cur][i];
if (!inq[i])
{
inq[i] = true;
++cnt[i];
if (cnt[i] > n) return true;
q.push(i);
}
}
}
}
return false;
} int main()
{ read(n); read(m); read(k);
for (int i = ; i <= n; i++)
{
for (int j = ; j <= * k; j++)
{
ll x;
read(x);
if (j & ) B[i][(j + ) >> ] = x;
else S[i][j >> ] = x;
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
for (int x = ; x <= k; x++)
{
if (B[i][x] != - && S[j][x] != -)
chkmax(cst[i][j] , S[j][x] - B[i][x]);
}
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
dist[i][j] = inf;
}
}
for (int i = ; i <= m; i++)
{
int u , v;
ll w;
read(u); read(v); read(w);
chkmin(dist[u][v] , w);
}
for (int x = ; x <= n; x++)
{
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
chkmin(dist[i][j] , dist[i][x] + dist[x][j]);
}
}
}
double l = , r = , ans = ;
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
chkmax(r , (double)cst[i][j]);
}
}
while (r - l > EPS)
{
double mid = (l + r) / 2.0;
if (check(mid))
{
l = mid;
ans = mid;
} else r = mid;
}
printf("%lld\n" , (ll)ans); return ; }

[APIO 2017] 商旅的更多相关文章

  1. APIO 2017 商旅 洛谷3778

    Description 在广阔的澳大利亚内陆地区长途跋涉后,你孤身一人带着一个背包来到了科巴.你被这个城市发达而美丽的市场所 深深吸引,决定定居于此,做一个商人.科巴有个集市,集市用从1到N的整数编号 ...

  2. APIO 2017 游记

    //第一次写游记,只是流水账...结果好像确实只去游了…… day-11 省选挂了,即将退役……(然而apio之后得知并没有退役,感谢放我一条活路)(吐槽出题人考完才造数据,题目没有子任务之类的玩意, ...

  3. CTSC&APIO 2017游记

    Day 0 早上4点多起床赶飞机,起床的时候发现闹钟调成下午4点的了...(虽然说早就已经被父母的洗漱声音吵醒了) 飞机上碎觉.到了北京发现比福州还热...而且北京今天意外地好天气,没有传言中的&qu ...

  4. AtCoder Grand Contest 015 题解

    A - A+...+B Problem 常识 Problem Statement Snuke has N integers. Among them, the smallest is A, and th ...

  5. HAOI 2017 游记

    省选 2017年4月23日 流水账式游记,不喜勿喷. Day0: 准备出发,上午敲了一顿板子,板子敲完了就打小游戏,老师也不管了. 过程中各种奶,说什么今年一定考仙人掌啦,今年一定考字符串啦,今年一定 ...

  6. CI Weekly #10 | 2017 DevOps 趋势预测

    2016 年的最后几个工作日,我们对 flow.ci Android & iOS 项目做了一些优化与修复: iOS 镜像 cocoapods 版本更新: fir iOS上传插件时间问题修复: ...

  7. 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS

    一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...

  8. iOS的ATS配置 - 2017年前ATS规定的适配

    苹果规定 从2017年1月1日起,新提交的 app 不允许使用NSAllowsArbitraryLoads来绕过ATS(全称:App Transport Security)的限制. 以前为了能兼容ht ...

  9. 深入研究Visual studio 2017 RC新特性

    在[Xamarin+Prism开发详解三:Visual studio 2017 RC初体验]中分享了Visual studio 2017RC的大致情况,同时也发现大家对新的Visual Studio很 ...

随机推荐

  1. AngularJS的简单表单验证

    代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsCheckSimpleForm.rar 代码: <!DOCTYPE HTM ...

  2. mysql用户修改登录密码及授予用户远程登录权限

    一.修改用户登录密码: mysql> show databases;ERROR 1820 (HY000): You must SET PASSWORD before executing this ...

  3. POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)

    题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...

  4. Mtk Camera

    MTK6577+Android之Camera驱动 http://blog.csdn.net/loongembedded/article/details/41695205 MTK Camera 开机启动 ...

  5. 网页编程-Djiango(二)

    一.初始Ajax ajax的写法: $.ajax({ url:'/host', type:'POST' data:{'k1':123,'k2':'root'} success:function(dat ...

  6. h5页面测试

    转自:http://www.blogjava.net/qileilove/archive/2014/07/24/416154.html?utm_source=tuicool&utm_mediu ...

  7. SegmentFault 巨献 1024 程序猿游戏「红岸的呼唤」第二天任务攻略

    眼看实验室就要关门了.走之前写一下解题过程(事实上大家都等着第三题出来吧大概-=). 高速传送门:http://segmentfault.com/game/2 那么接昨天的博客,今天的题目是这种: 完 ...

  8. 九度OJ 1121:首字母大写 (字符串处理)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2865 解决:1007 题目描述: 对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母. 在字符串中,单词 ...

  9. Find out when memory leaks are a concern and how to prevent them

    Handling memory leaks in Java programs Find out when memory leaks are a concern and how to prevent t ...

  10. Android笔记之启动界面的设置

    默认情况下,启动界面是白屏 我们自定义一个启动界面如下,3秒钟后进入主界面并结束启动页 SplashActivity.java package com.bu_ish.myapp; import and ...