MUTC 2 D - Power transmission 最短路

来源:互联网 发布:丝绸之路 商品数据 编辑:程序博客网 时间:2024/05/16 18:04

Power transmission

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1403    Accepted Submission(s): 533


Problem Description
The project West-East power transmission is famous around the world. It transmits the electricity from western areas to east China. There are many nodes in the power system. Each node is connected with several other nodes in the system by cable. Power can be only transmitted between two connected nodes. For each node, it can’t send power to two or more other nodes at the same time. 
As we have all known, power will be loss during the transmission. Bob is the chief engineer of the project. He wants to build a transmission line which send power from one node to another node and minimize the power loss at the same time. Now he asks you to help him solve the problem.
 

Input
There are several test cases. For each test case, the first line contains an integer N (0 < N ≤ 50000) which represents the number of nodes in the power system. Then there will be N groups of data following. For the i-th(0 < i ≤ N) group, the first line is an integer ki (ki ≤ 50), which means the node i is connected with ki nodes. The rest of the i-th group data are divided into ki lines. Each line contains an integer ai (0 < ai ≤ N, ai ≠ i) and an integer bi (0 ≤ bi ≤ 100), which represents power can be transmitted from node i to ai and will loss bi% while transmitting. The last line of input data contains three integers separated by single spaces. The first one is s, the second is t (0 < s, t ≤ N), and the third is the total power M (0 < M ≤ 10^6) at node s.
 

Output
For each test case, output the minimum of loss power while transmitting from node s to node t. The result should be printed with two digits to the right of the decimal point. If power cannot be transmitted from node s to node t, output “IMPOSSIBLE!” in a line.
 

Sample Input
422 503 7021 304 2021 104 4001 4 100
 

Sample Output
60.00
Hint
In the sample, the best transmission line is 1 -> 2 -> 4, loss power is 100 * 50% + 100 * (100%-50%)*20% = 60.00
 

Author
TJU
 

Source
2012 Multi-University Training Contest 2
 

Recommend
zhuyuanchen520
 

--------------------

最小消耗即最大剩余。

选一条路径使(1-b1%)*(1-b2%)....*(1-bm%)最大

堆优化的dijkstra或spfa皆可

--------------------

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>using namespace std;const int maxn=55555;const int maxm=111111111;const double OO=1e30;struct HeapNode{    double d;    int u;    bool operator<(const HeapNode& rhs) const    {        return d<rhs.d;    }};struct EDGENODE{    int to;    int w;    int next;}edges[maxm];int edge,head[maxn];void addedge(int u,int v,int c){    edges[edge].w=c,edges[edge].to=v,edges[edge].next=head[u],head[u]=edge++;}void init(){    memset(head,-1,sizeof(head));    edge=0;}int n;double dist[maxn];bool visit[maxn]= {0};/*void dijkstra(int src){    int u,v,w;    double _max;    memset(visit,0,sizeof(visit));    memset(dist,0,sizeof(dist));    dist[src]=1;    for (int loop=1; loop<=n; loop++)    {        //cerr<<loop<<endl;        u=0;        _max=0.0;        for (int i=1; i<=n; i++)        {            //printf("%0.2lf ",dist[i]);            if (!visit[i]&&dist[i]>_max)            {                _max=dist[i];                u=i;            }        }        //printf("\n");        if (u==0) return;        visit[u]=true;        for (int i=head[u];i!=-1;i=edges[i].next)        {            v=edges[i].to;            w=edges[i].w;            if (!visit[v]&&dist[u]*(1.0-(double)w/100.0)>dist[v])            {                dist[v]=dist[u]*(1.0-(double)w/100.0);            }        }    }}*/void dijkstra(int src){    int u,v,w;    priority_queue<HeapNode>que;    memset(visit,0,sizeof(visit));    memset(dist,0,sizeof(dist));    dist[src]=1;    que.push((HeapNode){0,src});    while (!que.empty())    {        HeapNode x=que.top();        que.pop();        u=x.u;        if (visit[u]) continue;        visit[u]=true;        for (int i=head[u]; i!=-1; i=edges[i].next)        {            v=edges[i].to;            w=edges[i].w;            if (dist[u]*(1.0-(double)w/100.0)>dist[v])            {                dist[v]=dist[u]*(1.0-(double)w/100.0);                que.push((HeapNode){dist[v],v});            }        }    }}/*bool spfa(int node,int src,int head[],EDGENODE edges[],double dist[]){    int i,l,r,u,v,w;    bool visit[maxn];    int q[maxn],outque[maxn];    memset(visit,0,sizeof(visit));    memset(outque,0,sizeof(outque));    for (int i=0; i<=node; i++) dist[i]=0;    r=0;    q[r++]=src;    dist[src]=1;    visit[src]=true;    for (l=0; l!=r; ( (++l>=maxn)?(l=0):(1) ))    {        u=q[l];        visit[u]=false;        outque[u]++;        if (outque[u]>node) return false;        for (i=head[u]; i!=-1; i=edges[i].next)        {            v=edges[i].to;            w=edges[i].w;            if (dist[u]*(1.0-(double)w/100.0)>dist[v])            {                dist[v]=dist[u]*(1.0-(double)w/100.0);                if (visit[v]) continue;                q[r++]=v;                visit[v]=true;                if (r>=maxn) r=0;            }        }    }    return true;}*/int main(){    int t;    int src,dest;    int M;    //freopen("abc.in","r",stdin);    //freopen("abc.out","w",stdout);    while (~scanf("%d",&n))    {        init();        for (int u=1; u<=n; u++)        {            scanf("%d",&t);            while (t--)            {                int v,c;                scanf("%d%d",&v,&c);                addedge(u,v,c);            }        }        scanf("%d%d%d",&src,&dest,&M);        dijkstra(src);        //spfa(n,src,head,edges,dist);        if (dist[dest]>0.000001) printf("%0.2lf\n",M-dist[dest]*M);        else printf("IMPOSSIBLE!\n");    }    return 0;}







原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 4岁宝宝打呼噜怎么办 宝宝感冒拒奶怎么办 新生儿吸奶无力怎么办 吃奶小牛肚子胀怎么办 新生儿吃奶后打嗝怎么办 新生儿吃多漾奶怎么办 婴儿总是睡不熟怎么办 新生儿不不吃奶怎么办 学生沉迷网络游戏班主怎么办 手机用不了卡怎么办 手机变竖屏怎么办 游戏不支持分屏怎么办 服装设计做到没思路怎么办 眼睛变单眼皮了怎么办 换手机号银行卡绑定怎么办 麦当劳mdp改版了怎么办 摆摊做小吃下雨怎么办 cad2014画图很卡怎么办 头皮有毛囊虫怎么办 头发上的毛囊炎怎么办 狗笼子里面拉屎怎么办 地图鱼起白点怎么办 初中学不好高中怎么办 初中孩子英语不好怎么办 初中孩子数学不好怎么办 万能声卡声音小怎么办 营业执照显示经营异常怎么办 暑假教育培训证怎么办 账套引入失败怎么办 报税报错了怎么办 税盘一年没抄税怎么办 初级会计证没领怎么办 房贷没有流水账怎么办 锦州银行倒闭了怎么办 认缴期限过了怎么办 吃了假猪血怎么办 橡皮泥粘头发上怎么办 遇到难相处同事怎么办 遇到奇葩家长怎么办啊! 过期的孕妇奶粉怎么办 肝脏造血功能差怎么办