bzoj千题计划227:bzoj1486: [HNOI2009]最小圈
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
1 2 5
2 3 5
3 1 5
2 4 3
4 1 3
Sample Output
bzoj千题计划227:bzoj1486: [HNOI2009]最小圈的更多相关文章
- BZOJ1486 HNOI2009 最小圈 【01分数规划】
BZOJ1486 HNOI2009 最小圈 Description 应该算是01分数规划的裸板题了吧..但是第一次写还是遇到了一些困难,vis数组不清零之类的 假设一个答案成立,那么一定可以找到一个环 ...
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划322:bzoj2561: 最小生成树(最小割)
https://www.lydsy.com/JudgeOnline/problem.php?id=2561 考虑Kruscal算法求最小生成树的流程 如果 u和v之间的长为L的边能出现在最小生成树里, ...
- bzoj千题计划209:bzoj1185: [HNOI2007]最小矩形覆盖
http://www.lydsy.com/JudgeOnline/problem.php?id=1185 题解去看它 http://www.cnblogs.com/TheRoadToTheGold/p ...
- bzoj千题计划140:bzoj4519: [Cqoi2016]不同的最小割
http://www.lydsy.com/JudgeOnline/problem.php?id=4519 最小割树 #include<queue> #include<cstdio&g ...
- bzoj千题计划139:bzoj2229: [Zjoi2011]最小割
http://www.lydsy.com/JudgeOnline/problem.php?id=2229 最小割树介绍:http://blog.csdn.net/jyxjyx27/article/de ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划274:bzoj3779: 重组病毒
http://www.lydsy.com/JudgeOnline/problem.php?id=3779 有一棵树,初始每个节点有不同的颜色 操作1:根节点到x的路径上的点 染上一种没有出现过的颜色 ...
随机推荐
- 解决SSH登录用户执行的命令部分环境变量参数不生效的问题
问题概况 linux机器在/etc/profile配置完成环境变量后,SSH到目标机器执行命令,但是获取不到已配置的环境变量值. 例如场景: 在/etc/profile配置了http代理 export ...
- gym101522 [小熊骑士限定]La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017
西瓜队(划掉),Kuma Rider久违的第一场训练,四小时瞎打.jpg A.水题,排序 #include<cstdio> #include<iostream> #includ ...
- Estimation And Gain
Estimation: Almost every is spent on ergod the text and build the dictionary. Gains: I have never us ...
- Leetcode题库——47.全排列II
@author: ZZQ @software: PyCharm @file: permuteUnique.py @time: 2018/11/16 13:34 要求:给定一个可包含重复数字的序列,返回 ...
- nodemoduleOfCheerio
https://www.npmjs.com/package/cheerio 这是npm的api说明 英文好的同学可以去看看. cheerioAPI 是一个用来操作jsDOM的模块: 就像jQuery一 ...
- C++ STL 整理
一.一般介绍 STL(Standard Template Library),即标准模板库,是一个具有工业强度的,高效的C++程序库.它被容纳于C++标准程序库(C++ Standard Library ...
- OneZero第四周——预完成功能点统计
本周OneZero将完成“统计”功能. 功能点统计如下: 1.主页单击记录,进入修改界面,修改记录. 2.主页长按记录,出现删除按钮,删除记录. 3.全部记录按分类进行饼图显示. 4.全部记录按分类进 ...
- javascript extend
interface Date{ addHours(h:number); addMinutes(m:number); format(str):string } interface String{ tri ...
- 美团 OCTO 分布式服务治理系统
OCTO 是美团千亿调用量的分布式服务通信框架及服务治理的系统,可实现服务注册.服务自动发现.服务管理.容错处理.数据可视化.服务监控报警.服务分组等.本文总结了 OCTO 架构原理.Java 应用的 ...
- MyBatis关联查询,一对一关联查询
数据库E-R关系 实体类 public class City { Long id; String name; Long countryId; Date lastUpdate; } public cla ...