Power transmission【有向图】
2012-08-03 19:02
176 查看
View Code
Power transmission 有向图问题
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
4
2
2 50
3 70
2
1 30
4 20
2
1 10
4 40
0
1 4 100
Sample Output
60.00
#include<iostream> #include<iomanip> #include<cstdio> #include<queue> using namespace std; struct node{ int dest; double value; node* next; node() { next=NULL; } }edge[50010];//构造点 int n,s,t; double power; double len[50010]; node temp[2500010]; queue<int> ans; void bfs() { int index; node* p; ans.push(s); while(!ans.empty()) { index=ans.front(); ans.pop(); p=edge[index].next;//取出第一个相邻的点 while(p!=NULL) { if(len[p->dest]<len[index]*(p->value))//这个点的能量比从上一个点传过来的能量要小 { // cout<<p->dest<<" "<<len[p->dest]<<" "<<index<<" "<<len[index]<<" "<<p->value<<endl; ans.push(p->dest);cout<<p->dest<<endl; len[p->dest]=len[index]*(p->value);//换成能量大的 } p=p->next;//找下一个相邻的点h } } //cout<<len[1]<<" "<<len[2]<<" "<<len[3]<<" "<<len[4]<<endl; } int main() { int i,j,k; int x; double y; node* p; while(scanf("%d",&n)!=EOF) { for(i=1,j=0;i<=n;i++) { len[i]=0; scanf("%d",&k); while(k--) { scanf("%d%lf",&x,&y); p=&temp[j++]; p->dest=x; p->value=(100-y)/100; p->next=edge[i].next; edge[i].next=p; } } scanf("%d%d%lf",&s,&t,&power);//1 4 100 len[s]=power;//在点的剩余能量 bfs(); if(len[t]==0) cout<<"IMPOSSIBLE!"<<endl; else cout<<setiosflags(ios::fixed)<<setprecision(2)<<(len[s]-len[t])<<endl; for(i=0;i<j;i++) { temp[i].next=NULL; } for(i=0;i<n;i++) { edge[i].next=NULL; } } return 0; }
Power transmission 有向图问题
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
4
2
2 50
3 70
2
1 30
4 20
2
1 10
4 40
0
1 4 100
Sample Output
60.00
相关文章推荐
- hdu 4318 Power transmission(最短路)
- UVA 10330 Power Transmission 网络流 拆点+多源点多汇点
- UVA 10330 Power Transmission(网络最大流)
- UVa10330 Power Transmission (最大流,拆点)
- HDOJ&nbsp;&nbsp;4318&nbsp;&nbsp;&nbsp;&nbsp;Power&nbsp;transmission
- HDU OJ 4318 Power transmission【最短路spfa】
- HDU 4318 Power transmission (dijkstra && 邻接表从队友那里抄来的,当作模板吧)
- hdu 4318 Power transmission 临接表 广搜 多校联合赛(二) 第九题
- 最短路 Power transmission 用的邻表 spfa
- LightOJ 1155 - Power Transmission【拆点网络流】
- lightoj 1155 - Power Transmission 【多源多汇 拆点网络流】
- hdu - 4318 - Power transmission - 最短路+贪心
- HDU 4318 Power transmission 最长路 (dijkstra + 优先队列) 水
- 10330 - Power Transmission (最大流)
- uva 10330 Power Transmission (网络流)
- UVa 10330 Power Transmission (最大流+多源多汇点+结点容量(拆点))
- MUTC 2 D - Power transmission 最短路
- uva 10330 - Power Transmission(网络流)
- uva 10330 Power Transmission (网络流)
- MUTC 2 D - Power transmission 最短路