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.
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.00HintIn 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;}
- MUTC 2 D - Power transmission 最短路
- hdu 4318 Power transmission(最短路)
- HDU 4318 Power transmission(最短路变形)
- HDU OJ 4318 Power transmission【最短路spfa】
- hdu - 4318 - Power transmission - 最短路+贪心
- hdu4318 Power transmission 最短路 当数据很大的时候的解决办法 一道题目的解题全过程记录 小水
- MUTC 2 D - Matrix 并查集
- uva 10330 - Power Transmission
- SPFA: Power Transmission
- hdu 4318 Power transmission
- hdu 4318 Power transmission
- HDU 4318 Power transmission
- 10330 - Power Transmission
- HDU 4318 Power transmission
- UVa:10330 Power Transmission
- UVa10330 Power Transmission
- HDU-4318-Power transmission
- uva 10330Power Transmission
- 软件构件与中间件
- 泛型、反射使用 比较类型 为类的属性赋值
- 界面的语言——图标与文案的二重奏
- oracle10g版本不再支持
- Wiki OI 1026 逃跑的拉尔夫
- MUTC 2 D - Power transmission 最短路
- 理解堆和栈的区别
- UI应遵循的三大网站设计原则
- C#学习笔记之垃圾回收机制
- 如何运用卷影副本服务(VSS)备份虚拟机快照?
- Ogre碰撞检测,精确到物体网格三角面
- dB与dBm
- 测试access control
- [Accessibility] Missing contentDescription attribute on "View"