[POJ 3621] Sighting Cows
01分数规划的基本裸题。
因为路线一定是个环,所以找个最优比率生成环即可
二分一个比值,check一下即可。
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=1005;
int l,p,a[1005],inq[1005],cnt[1005],head[1005],ecnt;
struct Edge{int to,nxt,val;}e[N<<3];
void add(int bg,int ed,int val){e[++ecnt].nxt=head[bg];e[ecnt].to=ed;e[ecnt].val=val;head[bg]=ecnt;}
double dis[1005];
bool ck(double x){
queue<int>q;
for(int i=1;i<=l;i++) q.push(i),dis[i]=0,inq[i]=1,cnt[i]=1;
while(!q.empty()){
int u=q.front();q.pop();inq[u]=0;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;double dist=e[i].val;
if(dis[v]>(double)dis[u]+x*dist-(double)a[u]){
dis[v]=dis[u]+x*dist-(double)a[u];
if(!inq[v]) q.push(v),inq[v]=1,cnt[v]++;
if(cnt[v]>=l)return 1;
}
}
}return 0;
}
int main() {
scanf("%d%d",&l,&p);
for(int i=1;i<=l;i++) scanf("%d",&a[i]);
for(int u,v,b,i=1;i<=p;i++)
scanf("%d%d%d",&u,&v,&b),add(u,v,b);
double l=0,r=10000000,mid;
while(r-l>1e-4){
mid=(l+r)/2;
if(ck(mid)) l=mid;
else r=mid;
}
printf("%.2lf",l);
}
[POJ 3621] Sighting Cows的更多相关文章
- POJ 3621 Sightseeing Cows 【01分数规划+spfa判正环】
题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ 3621 Sightseeing Cows(最优比例环+SPFA检测)
Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10306 Accepted: 3519 ...
- POJ 3621 Sightseeing Cows | 01分数规划
题目: http://poj.org/problem?id=3621 题解: 二分答案,检查有没有负环 #include<cstdio> #include<algorithm> ...
- [POJ 3621] Sightseeing Cows
[题目链接] http://poj.org/problem?id=3621 [算法] 01分数规划(最优比率环) [代码] #include <algorithm> #include &l ...
- POJ 3621 Sightseeing Cows 01分数规划,最优比例环的问题
http://www.cnblogs.com/wally/p/3228171.html 题解请戳上面 然后对于01规划的总结 1:对于一个表,求最优比例 这种就是每个点位有benefit和cost,这 ...
- POJ 3621 Sightseeing Cows [最优比率环]
感觉去年9月的自己好$naive$ http://www.cnblogs.com/candy99/p/5868948.html 现在不也是嘛 裸题,具体看学习笔记 二分答案之后判负环就行了 $dfs$ ...
- POJ 3621 Sightseeing Cows (bellman-Ford + 01分数规划)
题意:给出 n 个点 m 条有向边,要求选出一个环,使得这上面 点权和/边权和 最大. 析:同样转成是01分数规划的形式,F / L 要这个值最大,也就是 G(r) = F - L * r 这个值为0 ...
- POJ 3621 Sightseeing Cows (最优比率环 01分数划分)
题意: 给定L个点, P条边的有向图, 每个点有一个价值, 但只在第一经过获得, 每条边有一个花费, 每次经过都要付出这个花费, 在图中找出一个环, 使得价值之和/花费之和 最大 分析: 这道题其实并 ...
- poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分
poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...
随机推荐
- C#--线程池与线程的种类
.NET CLR线程的种类 至少3个线程:主线程.调试线程.终结器线程 1.main thread 2.worker thread 3.finalizer thread 4.debugger help ...
- POJ 1106
先判断是否在圆内,然后用叉积判断是否在180度内.枚举判断就可以了... 感觉是数据弱了.. #include <iostream> #include <cstdio> #in ...
- jdbc 读取oracle long raw 字段,里面存的是文本
jdbc 读取oracle long raw 字段,里面存的是文本 参考: http://singlewolf.iteye.com/blog/278769 http://blog.csdn.net/r ...
- Qt的Socket数据通讯的一个样例。
QTcpServer类 用来侦听port ,获取QTcpSocket. QTcpSocket有 connected的信号(已经连接),还有readyread()信号,表示已经有数据发过来了.准备读取 ...
- LeetCode96_Unique Binary Search Trees(求1到n这些节点能够组成多少种不同的二叉查找树) Java题解
题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For e ...
- ioctl方法详解
设备控制接口(ioctl 函数)回想一下我们在字符设备驱动中介绍的struct file_operations 结构,这里我们将介绍一个新的方法: int (*ioctl) (struct inode ...
- python spark 决策树 入门demo
Refer to the DecisionTree Python docs and DecisionTreeModel Python docs for more details on the API. ...
- Python笔记(十一)——数据抓取例子
上班时候想看股票行情怎么办?试试这个小例子,5分钟拉去一次股票价格,预警: #coding=utf-8 import re import urllib2 import time import thre ...
- FlappyBird模拟(不完整版本)
FlappyBird模拟(不完整版本) 准备材料 land地 sky天 pipe管道 bird小鸟 Land.js function Land(info) { this.x = info.x; thi ...
- Java I/O streams
I/O Streams Byte Streams 输入输出以字节为单位,所有的使用字节流的类都继承自 InputStream 和 OutputStream. Byte Streams 属于 low-l ...