简单的一题,使用类DIJK的算法就可以了。

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std; struct Edge{
int u,v;
double lose;
int next;
}edge[2500050];
int head[50010]; bool vis[50010];
int tot;
void addedge(int u,int v,double l){
edge[tot].u=u;
edge[tot].v=v;
edge[tot].lose=l;
edge[tot].next=head[u];
head[u]=tot++;
}
double dist[50010];
struct point{
int node;
double power;
bool operator < (const point &p)const {
return power<p.power;
}
}pushed,tmp;
priority_queue<point>que; int main(){
int n,v,l,f,t; double M;
while(scanf("%d",&n)!=EOF){
int k; tot=0;
for(int i=1;i<=n;i++){
head[i]=-1;
vis[i]=false;
dist[i]=0;
}
for(int u=1;u<=n;u++){
scanf("%d",&k);
for(int p=1;p<=k;p++){
scanf("%d%d",&v,&l);
addedge(u,v,l*1.0);
}
}
scanf("%d%d%lf",&f,&t,&M);
tmp.node=f; tmp.power=M;
dist[f]=M;
que.push(tmp);
while(!que.empty()){
tmp=que.top();
if(tmp.node==t) break;
que.pop();
if(vis[tmp.node])
continue;
vis[tmp.node]=true;
for(int e=head[tmp.node];e!=-1;e=edge[e].next){
if(!vis[edge[e].v]){
if(tmp.power*(1-edge[e].lose*1.0/100)>dist[edge[e].v]){
dist[edge[e].v]=tmp.power*(1-edge[e].lose*1.0/100);
pushed.node=edge[e].v; pushed.power=dist[edge[e].v];
que.push(pushed);
}
}
}
}
if(dist[t]<1e-8)
printf("IMPOSSIBLE!\n");
else printf("%.2lf\n",M-dist[t]);
while(!que.empty())
que.pop();
}
return 0;
}

  

HDU 4318 Contest 2的更多相关文章

  1. HDU 4318 Power transmission(最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=4318 题意: 给出运输路线,每条路线运输时都会损失一定百分比的量,给定起点.终点和初始运输量,问最后到达终点时最 ...

  2. HDU 5045 Contest(状压DP)

    Problem Description In the ACM International Collegiate Programming Contest, each team consist of th ...

  3. hdu - 5045 - Contest(国家压缩dp)

    意甲冠军:N个人M通过主打歌有自己的期望,每个问题发送人玩.它不能超过随机播放的次数1,追求最大业绩预期 (1 ≤ N ≤ 10,1 ≤ M ≤ 1000). 主题链接:pid=5045" ...

  4. [ACM] hdu 5045 Contest (减少国家Dp)

    Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...

  5. HDU–5988-Coding Contest(最小费用最大流变形)

    Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  6. hdu 5045 Contest(状态压缩DP)

    题解:我们使用一个二位数组dp[i][j]记录进行到第i个任务时,人组合为j时的最大和(这里的j我们用二进制的每位相应一个人). 详细见代码: #include <iostream> #i ...

  7. HDU 5045 Contest

    pid=5045">主题链接~~> 做题感悟:比赛时这题后来才写的,有点小尴尬.两个人商议着写写了非常久才写出来,I want to Powerful ,I believe me ...

  8. HDU 4335 Contest 4

    利用降幂公式..呃,还是自己去搜题解吧.知道降幂公式后,就不难了. #include <iostream> #include <cstdio> #include <alg ...

  9. HDU 4339 Contest 4

    树状数组,主要是抓住要求连续1的个数.这样,初始时,相同的加1,不同的加0. 查询时,用二分搜索右边界.就是比较当前mid-l+1的值与他们之间1的个数(这可以通过树状数组求区间和得出),记录右边界即 ...

随机推荐

  1. [SharePoint][SharePoint Designer 入门经典]Chapter13 客户端JavaScript编程

    1.创建客户对象模型的页面 2.使用CAML从SPS中取得数据 3.创建更新删除列表项目 4.为ribbon添加项目

  2. crm高速开发之Entity

    我们在后台代码里面操作Entity的时候,基本上是这样写的: /* 创建者:菜刀居士的博客  * 创建日期:2014年07月5号  */ namespace Net.CRM.Entity {     ...

  3. [iOS翻译]《iOS7 by Tutorials》在Xcode 5里使用单元測试(上)

    简单介绍: 单元測试是软件开发的一个重要方面.毕竟,单元測试能够帮你找到bug和崩溃原因,而程序崩溃是Apple在审查时拒绝app上架的首要原因. 单元測试不是万能的,但Apple把它作为开发工具包的 ...

  4. ZOJ 2913 Bus Pass (近期的最远BFS HDU2377)

    题意  在全部城市中找一个中心满足这个中心到全部公交网站距离的最大值最小 输出最小距离和满足最小距离编号最小的中心 最基础的BFS  对每一个公交网站BFS  dis[i]表示编号为i的点到全部公交网 ...

  5. python spark kmeans demo

    官方的demo from numpy import array from math import sqrt from pyspark import SparkContext from pyspark. ...

  6. springmvc-mvc:resource标签使用

    转自:http://www.cnblogs.com/gzulmc/p/6746174.html <!-- 配置静态资源 --><mvc:resources location=&quo ...

  7. Java线程池原理与架构分析

    /** * 一.线程池:提供了一个线程队列,队列中保存着所有等待状态的线程.避免了创建与销毁额外开销,提高了响应速度 * 二.线程池的体系结构 * java.util.concurrent.Execu ...

  8. Ubuntu下安装tim/QQ/微信

    一.安装deepin-wine环境: 上https://github.com/wszqkzqk/deepin-wine-ubuntu页面下载zip包(或用git方式克隆),在“下载”目录下原地解压即可 ...

  9. BZOJ 3238 后缀数组+单调栈

    单调栈跑两遍求出来 ht[i]为最小值的那段区间 //By SiriusRen #include <cstdio> #include <cstring> #include &l ...

  10. autocomplete for password

    <input id="userPassword" type="password" autocomplete="current-password& ...