Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 3129  Solved: 1543
[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
 
二分法+spfa_dfs最小圈
可以经过计算在T=60次循环后,答案精度会在小数点后8位
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std; const int MAXN=;
struct Edge
{
int to,next;
double w;
}E[MAXN];
int node,head[MAXN];
double dist[MAXN];
bool flag,vis[MAXN];
int n,m;
double mid; void insert(int u,int v,double w)
{
E[++node]=(Edge){v,head[u],w};head[u]=node;
} void spfa_dfs(int s)
{
vis[s]=;
for(int i=head[s];i;i=E[i].next)
{
if(dist[E[i].to]>dist[s]+E[i].w-mid)
{
if(vis[E[i].to]){flag=;return;}
else
{
dist[E[i].to]=dist[s]+E[i].w-mid;
spfa_dfs(E[i].to);
}
}
}
vis[s]=;
} bool check()
{
flag=;
memset(dist,,sizeof(dist));
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
dist[i]=;
spfa_dfs(i);
if(flag) return ;
}
return ;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
insert(u,v,w);
}
double l=-1e7,r=1e7;
int T=;
while(T--)
{
mid=(l+r)/;
if(check()) r=mid;
else l=mid;
}
printf("%.8lf",r);
return ;
}

1486: [HNOI2009]最小圈的更多相关文章

  1. bzoj 1486: [HNOI2009]最小圈 dfs求负环

    1486: [HNOI2009]最小圈 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1022  Solved: 487[Submit][Status] ...

  2. BZOJ 1486: [HNOI2009]最小圈( 二分答案 + dfs判负圈 )

    二分答案m, 然后全部边权减掉m, 假如存在负圈, 那么说明有平均值更小的圈存在. 负圈用dfs判断. ------------------------------------------------ ...

  3. [BZOJ 1486][HNOI2009]最小圈(二分答案+dfs写的spfa判负环)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1486 分析:容易想到先二分答案x,然后把所有边的权值-x,那么如果图中存在权值和为0的 ...

  4. BZOJ 1486: [HNOI2009]最小圈 [01分数规划]

    裸题...平均权值最小的环.... 注意$dfs-spfa$时$dfs(cl)$...不要写成$dfs(u)$ #include <iostream> #include <cstdi ...

  5. 1486: [HNOI2009]最小圈 - BZOJ

      在机房的小伙伴提醒是二分之后,我想到了是判负环,所以我用spfa,而且我保持dis都是小于等于0,本以为这样就能过了,可是还是有一个点达到了3.8s左右(其他都是0.0几秒) 所以还是写了dfs版 ...

  6. bzoj 1486: [HNOI2009]最小圈

    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 HIN ...

  7. 【BZOJ】1486 [HNOI2009]最小圈

    [算法]二分+spfa [题解]据说这个叫分数规划? 0-1分数规划 二分答案a,则对于任意的环有w/k≤a即w-ak≤0,若满足条件则a变小,否则a变大. 因为w=w1+w2+...+wk,所以变形 ...

  8. bzoj千题计划227:bzoj1486: [HNOI2009]最小圈

    http://www.lydsy.com/JudgeOnline/problem.php?id=1486 二分答案 dfs版spfa判负环 #include<queue> #include ...

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

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

随机推荐

  1. My first python application

    ''' Authon:WSE_Gordon This application is use for the costomer to login the application. The Costome ...

  2. python中操作列表

    1.遍历列表 可以用for循环遍历打印非常实用 摸板: for 临时变量 in 列表 : print(临时变量) 注意缩进 , 注意冒号 2.创建数值列表 (1)使用range()函数 , 函数的范围 ...

  3. 对象大小对比之Comparable与Comparator

    一 概述 1.Comparable与Comparator使用背景 数值型数据(byte int short long float double)天生可对比大小,可排序,String实现了Compara ...

  4. 创建Python数据分析的Docker镜像+Docker自定义镜像commit,Dockerfile方式解析+pull,push,rmi操作

    实例解析Docker如何通过commit,Dockerfile两种方式自定义Dcoker镜像,对自定义镜像的pull,push,rmi等常用操作,通过实例创建一个Python数据分析开发环境的Dock ...

  5. 任务四:CSS定位和居中问题

    任务目标 实践HTML/CSS布局方式 深入了解position等CSS属性 任务描述 实现如 示例图(点击打开) 的效果 灰色元素水平垂直居中,有两个四分之一圆位于其左上角和右下角. 任务注意事项 ...

  6. CCF201803-1 跳一跳

    试题编号: 201803-1 试题名称: 跳一跳 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 近来,跳一跳这款小游戏风靡全国,受到不少玩家的喜爱. 简化后的跳一跳规则如下: ...

  7. Android学习——AsyncTask的使用

    AsyncTask是安卓自带的异步操作类,把异步操作简化并封装好,从而可以让开发者在子线程中更方便地更新UI. AsyncTask为一个抽象类,在继承AsyncTask时需要指定如下三个泛型参数:&l ...

  8. 面向对象设计中private,public,protected的访问控制原则及静态代码块的初始化顺序

    第一:private, public, protected访问标号的访问范围. private:只能由          1.该类中的函数          2.其友元函数访问 不能被任何其他访问,该 ...

  9. 数据质量控制软件Q-CHECKER(转)

    随着企业信息化建设的不断深入进行,我们的企业将逐步地发展成为数字化企业.其中作为最基本构成的CATIA数模已经是产品开发制造的唯一依据,CATIA数模的质量就是加工的质量,就是制造的质量,就是生产出的 ...

  10. 增强for循环 java.util.ConcurrentModificationException

    Java中的Iterator功能比较简单,并且只能单向移动: (1) 使用方法iterator()要求容器返回一个Iterator.第一次调用Iterator的next()方法时,它返回序列的第一个元 ...