hdu 4318 Power transmission

Power transmission

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


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
4 2 2 50 3 70 2 1 30 4 20 2 1 10 4 40 0 1 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
 

 

Source
 

 

Recommend
zhuyuanchen520
题意:题意:有一个发电站 s ,将电传送至  t , 有 许多路线可以走,每走 一条路 有损失,求埙失的最小值。
思路:(1)转化为 最短路问题,损失 = max- max*(1-a%)*(1-b%)……*(1-%n)(假设任意一条路线);
             (2)求的 (1-a%)*(1-b%)……*(1-%n)的最大值 即可。
             (3)现在 使 a 代替 1-a%,b 代替 1-b%……;即求 a*b*c*……*n的最大值!(注意::0<a<1……);
             (4)现在以e为底  取对数log a*b……*n 即log a +( log b)……+(log n) 有函数性质可知,log a 为 负值……log n 为负值。
              (5)求 【log a】+ log【b】+…………+【logn】 的最小值 即可(【】代表绝对值)这就成了 最短路
AC代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <queue>
#define INF 1000000000
using namespace std;
struct node
{
  int x;
  double y;
}tedge;
int m;
vector<node>edge[60000];
double dis[60000];
int vis[60000],cnt[60000];
void spfa( int s)
{
  queue<int>q;
  int i;
  memset(vis,0,sizeof(vis));
  memset(cnt,0,sizeof(cnt));
  for( i=1;i<=m;i++)
   dis[i]=INF;
  dis[s]=0;
  vis[s]=1;
  q.push(s);
  while(!q.empty( ))
  {
 int u=q.front( );
  q.pop( );
  vis[u]=0;
 for( i=0;i<edge[u].size( );i++)
 {
     int x1=edge[u][i].x;
     if(dis[x1]>dis[u]+edge[u][i].y)
     {
    dis[x1]=dis[u]+edge[u][i].y;
    if(!vis[x1])
    {
      q.push(x1);vis[x1]=1;
      if(++cnt[x1]>m) return ;
    }
  }
    }
 
  }
  return ;
}
int main( )
{
  int n,i,a;
  int xx,yy;
  int s,t;
  double M;
  while(~scanf("%d",&m))
  {
 for( i=1;i<=m;i++)
 edge[i].clear( );
 for( a=1;a<=m;a++)
    {
   scanf("%d",&n);
   while(n--)
   {
  scanf("%d%d",&xx,&yy);
  tedge.x=xx,tedge.y=-log((100.0-(double)yy)/100.0);
  edge[a].push_back(tedge);
   }
    }
    scanf("%d%d%lf",&s,&t,&M);
    spfa(s);
   // printf("t = %d dis[t] = %.2lf\n",t,dis[t]);
    if(dis[t]<INF)
    printf("%.2lf\n",M*(1-exp(-dis[t])));
    else puts("IMPOSSIBLE!");
  }
  return 0;
}
posted @ 2012-07-30 18:09  jiai  Views(277)  Comments(0Edit  收藏  举报