LOL新英雄皮肤弹丸天使点击就送

两种做法:

1.边的权值为手续费z,从b向a跑最短路,边跑边处理答案

2.边的权值为汇率,从a向b跑最短路,边跑边处理答案

#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
queue<double>q;
double path[],n,m,z,dis[],vis[];
int x,y,A,B,k;
struct node{
int u,v,nxt;
double w;
}edge[];
void add(int xx,int yy,double zz)
{
edge[++k].u =xx;
edge[k].v =yy;
edge[k].w =-zz/;
edge[k].nxt =path[xx];
path[xx]=k;
}
int main()
{
scanf("%lf%lf",&n,&m);
for(int i=;i<=m;++i)
{
scanf("%d%d%lf",&x,&y,&z);
add(y,x,z);add(x,y,z);
}
scanf("%d%d",&A,&B);
for(int i=;i<=n;++i)
dis[i]=0x3fff;
dis[B]=;vis[B]=;
q.push(B);
while(!q.empty())
{
int now=q.front() ;
q.pop() ;
vis[now]=; for(int i=path[now];i;i=edge[i].nxt )
{
if(dis[edge[i].v]>dis[edge[i].u]/edge[i].w)
{
dis[edge[i].v]=dis[edge[i].u]/edge[i].w;
if(!vis[edge[i].v])
{
q.push(edge[i].v );
vis[edge[i].v]=;
}
}
}
}
printf("%.8lf",dis[A]);
return ;
}

做法1

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
const int N=,M=1e6;
struct node{
int u,v,nxt;
double w;
}e[M<<];
int n,m,num,s,t,head[N];
double dis[N];
bool vis[N];
queue<int>q;
int qread()
{
int x=;
char ch=getchar();
while(ch<'' || ch>'')ch=getchar();
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x;
}
void Add(int u,int v,int w)
{
e[++num].u=u;
e[num].v=v;
e[num].w=1.0-w/100.0;
e[num].nxt=head[u];
head[u]=num;
}
void SPFA()
{
for(int i=;i<=n;++i)
dis[i]=100000.0;
dis[t]=;vis[t]=;
q.push(t);
int u,v;
while(!q.empty())
{
u=q.front();q.pop();
vis[u]=;
for(int i=head[u];i;i=e[i].nxt)
{
v=e[i].v;
if(dis[v]>dis[u]/e[i].w)
{
dis[v]=dis[u]/e[i].w;
if(!vis[v])
{
vis[v]=;
q.push(v);
}
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
int u,v,w;
for(int i=;i<=m;i++)
{
u=qread();v=qread();w=qread();
Add(u,v,w);
Add(v,u,w);
}
scanf("%d%d",&s,&t);
SPFA();
printf("%.8lf\n",dis[s]);
return ;
}

做法2

luoguP1576 最小花费的更多相关文章

  1. 把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend

    //把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend //dp[i][j]:把第i个数转成第j小的数,最小花费 //此题与po ...

  2. 把一个序列转换成非严格递增序列的最小花费 POJ 3666

    //把一个序列转换成非严格递增序列的最小花费 POJ 3666 //dp[i][j]:把第i个数转成第j小的数,最小花费 #include <iostream> #include < ...

  3. 第四届CCF软件能力认证(CSP2015) 第五题(最小花费)题解

    [问题描述] C国共有$n$个城市.有$n-1$条双向道路,每条道路连接两个城市,任意两个城市之间能互相到达.小R来到C国旅行,他共规划了$m$条旅行的路线, 第$i$条旅行路线的起点是$s_i$,终 ...

  4. 九度OJ 1086 最小花费--动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1086 题目描述: 在某条线路上有N个火车站,有三种距离的路程,L1,L2,L3,对应的价格为C1,C2,C3.其对 ...

  5. hdoj 3072 Intelligence System【求scc&&缩点】【求连通所有scc的最小花费】

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. ccf 201503-5 最小花费 这题交上去只有10分嗨!求大佬的题解啊

    问题描述 C国共有n个城市.有n-1条双向道路,每条道路连接两个城市,任意两个城市之间能互相到达.小R来到C国旅行,他共规划了m条旅行的路线,第i条旅行路线的起点是si,终点是ti.在旅行过程中,小R ...

  7. [LeetCode] Minimum Cost to Merge Stones 混合石子的最小花费

    There are N piles of stones arranged in a row.  The i-th pile has stones[i] stones. A move consists ...

  8. 1344:【例4-4】最小花费 dijkstra

    1344:[例4-4]最小花费 Dijkstra (1)a [ i ] [ j ] 存转账率(..转后所得率..) (2)dis [ i ] 也就是 a [ 起点 ] [ i ] (3)f [ i ] ...

  9. PTA 7-1 畅通工程之局部最小花费问题(35 分)

    7-1 畅通工程之局部最小花费问题(35 分) 某地区经过对城镇交通状况的调查,得到现有城镇间快速道路的统计数据,并提出“畅通工程”的目标:使整个地区任何两个城镇间都可以实现快速交通(但不一定有直接的 ...

随机推荐

  1. 「UER#2」谣言的传播

    「UER#2」谣言的传播 写了个乱搞,怎么莫名其妙就AC了,这...,之后又想了30min结合题解终于会证了. 首先最大值比较简单,记 \(f_i\) 为第 \(i\) 个点能到达的点数,上界 \(\ ...

  2. javaweb之添加学生信息

    1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求显示“• ”或“*”表示输入位数,密码要求八位以上字母.数字组成.(1分) 3性别:要求用单选框或下拉框 ...

  3. Java之路---Day04

    2019-10-18-21:35:36 面向对象 学面向对象前要先知道什么叫面向过程,了解了什么叫面向过程才容易理解面向对象 面向过程(强调步骤) 概念:当需要实现一个功能的时候,每一个具体的步骤都要 ...

  4. Java自学-数组 增强型for循环

    Java 中如何使用增强for循环 增强型for循环在遍历一个数组的时候会更加快捷 步骤 1 : 增强型for循环 注:增强型for循环只能用来取值,却不能用来修改数组里的值 public class ...

  5. kali之HexorBase数据库破解

    HexorBase 用户名密码连接数据库 暴力破解 点击底栏 Bruteforces Databases Servers , 然后会弹出一个新界面 Databases Bruteforces 新界面  ...

  6. js 将数字转换成中文大写

    //完成将 toChineseNum, 可以将数字转换成中文大写的表示,处理到万级别,例如 toChineseNum(12345),返回 一万二千三百四十五. const toChinesNum = ...

  7. 【WPF】EntityframeworkCore Update注意事项

    The instance of entity type 'Book' cannot be tracked because another instance with the same key valu ...

  8. 【等待事件】等待事件系列(5.1)--Enqueue(队列等待)

    [等待事件]等待事件系列(5.1)--Enqueue(队列等待)   1  BLOG文档结构图   2  前言部分   2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可 ...

  9. Cloudera Certified Associate Administrator案例之Manage篇

    Cloudera Certified Associate Administrator案例之Manage篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.下载Namenode镜像 ...

  10. 利用avicap32.dll实现的实时视频传输

    直接上代码吧! 在窗体上调用的类: using System; using System.Collections.Generic; using System.ComponentModel; using ...