http://www.lydsy.com/JudgeOnline/problem.php?id=1486

二分答案

dfs版spfa判负环

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream> #define N 3001
#define M 10001 using namespace std; int n; int tot,front[N],nxt[M],to[M];
double val[M]; double Val[M]; double dis[N];
bool vis[N]; bool tag; queue<int>q; int s; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void add(int u,int v,double w)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; val[tot]=w;
} void spfa(int u)
{
//if(tag) return;
int t;
for(int i=front[u];i;i=nxt[i])
{
t=to[i];
if(dis[u]+Val[i]<dis[t])
{
dis[t]=dis[u]+Val[i];
if(!vis[t])
{
vis[t]=true;
spfa(t);
vis[t]=false;
if(tag) return;
}
else
{
tag=true;
return;
}
}
}
} bool check(double mid)
{
for(int i=;i<=tot;++i) Val[i]=val[i]-mid;
tag=false;
for(int i=;i<=n;++i)
{
for(int j=;j<=n;++j) dis[j]=;
vis[i]=true;
spfa(i);
vis[i]=false;
if(tag) return true;
}
return false;
} int main()
{
int m;
read(n); read(m);
int u,v; double w;
while(m--)
{
read(u); read(v); scanf("%lf",&w);
add(u,v,w);
}
double l=-1e6,r=1e6,mid,ans;
int T=;
while(T--)
{
mid=(l+r)/;
if(!check(mid)) ans=l,l=mid;
else r=mid;
}
printf("%.8lf",ans);
}

1486: [HNOI2009]最小圈

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 2715  Solved: 1304
[Submit][Status][Discuss]

Description

Input

 

Output

 

Sample Input

4 5
1 2 5
2 3 5
3 1 5
2 4 3
4 1 3

Sample Output

3.66666667

bzoj千题计划227:bzoj1486: [HNOI2009]最小圈的更多相关文章

  1. BZOJ1486 HNOI2009 最小圈 【01分数规划】

    BZOJ1486 HNOI2009 最小圈 Description 应该算是01分数规划的裸板题了吧..但是第一次写还是遇到了一些困难,vis数组不清零之类的 假设一个答案成立,那么一定可以找到一个环 ...

  2. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  3. bzoj千题计划322:bzoj2561: 最小生成树(最小割)

    https://www.lydsy.com/JudgeOnline/problem.php?id=2561 考虑Kruscal算法求最小生成树的流程 如果 u和v之间的长为L的边能出现在最小生成树里, ...

  4. bzoj千题计划209:bzoj1185: [HNOI2007]最小矩形覆盖

    http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解去看它 http://www.cnblogs.com/TheRoadToTheGold/p ...

  5. bzoj千题计划140:bzoj4519: [Cqoi2016]不同的最小割

    http://www.lydsy.com/JudgeOnline/problem.php?id=4519 最小割树 #include<queue> #include<cstdio&g ...

  6. bzoj千题计划139:bzoj2229: [Zjoi2011]最小割

    http://www.lydsy.com/JudgeOnline/problem.php?id=2229 最小割树介绍:http://blog.csdn.net/jyxjyx27/article/de ...

  7. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  8. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  9. bzoj千题计划274:bzoj3779: 重组病毒

    http://www.lydsy.com/JudgeOnline/problem.php?id=3779 有一棵树,初始每个节点有不同的颜色 操作1:根节点到x的路径上的点 染上一种没有出现过的颜色 ...

随机推荐

  1. Flutter - 快速创建Stateless和Stateful组件

    1. 快速创建Stateless组件 输入stle,回车 class extends StatelessWidget { @override Widget build(BuildContext con ...

  2. Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别与用法

    Java容器类List.ArrayList.Vector及map.HashTable.HashMap的区别与用法 ArrayList 和Vector是采用数组方式存储数据,此数组元素数大于实际存储的数 ...

  3. 【Direct2D1.1初探】Direct2D特效概览

    转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 Direct2D是一个基于Direct3D的2D图形API,可以利用硬件加速特性来提供高性能高质量的2D渲染.但 ...

  4. 修炼内功_day01

    测试六段:    测试第一段:        - 能根据测试用例的描述步骤来执行用例        - 能对照用例的预期结果发现产品的问题        - 能够清晰准确的将问题记录下来后反馈给开发, ...

  5. Unity EasyTouch官方案例学习

    一.代码检测手势事件 1. EasyTouch4.x 写法 首先要手动在 Hierarchy 窗口添加 EasyTouch 物体,以触摸(Touch)手势为例,代码如下: using UnityEng ...

  6. 290. Word Pattern【LeetCode by java】

    今天发现LintCode页面刷新不出来了,所以就转战LeetCode.还是像以前一样,做题顺序:难度从低到高,每天至少一题. Given a pattern and a string str, fin ...

  7. 毕业回馈-89c52之最小系统

    今天分享一个51单片机最小系统的电路板设计(原理图+PCB) 技术手册上面对于51单片机最小系统作如下要求: 下载电路主要有以下几种: 采用RS-232转换器下载:(R1OUT-P3.0;T1IN-P ...

  8. PAT-1003 Emergency(Dijkstra)

    1003 Emergency (25 分) As an emergency rescue team leader of a city, you are given a special map of y ...

  9. Google C++ 编码规范

    刚刚看到一位博主的文章分享Google C++ 编码规范 本人做一下记录,方便以后学习.. 中文在线版本地址: http://zh-google-styleguide.readthedocs.io/e ...

  10. C. Smallest Word

    链接 [http://codeforces.com/contest/1043/problem/C] 题意 给你一个只包含a,b的字符串,有一种操作把第1个字符到第i个字符的子串进行反转,问要使最后字符 ...