zoukankan      html  css  js  c++  java
  • [HDU 4035] Maze

    膜kuangbin大爷

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define eps 1e-10//
     4 #define maxn 10005
     5 int cnt,v[maxn<<1],Next[maxn<<1],first[maxn];
     6 int T,n,Case;
     7 double K[maxn],E[maxn];
     8 struct Xi{
     9     double a,b,c,d;
    10     Xi operator+(Xi t){ 
    11         return (Xi){a+t.a,b+t.b,c+t.c,d+t.d}; 
    12     }
    13 };
    14 void add(int st,int end){
    15     v[++cnt]=end;
    16     Next[cnt]=first[st];
    17     first[st]=cnt;
    18 }
    19 Xi dfs(int x,int fa){
    20     bool flag=true;
    21     Xi ans,sum={0,0,0,fa?1.0:0.0};//
    22     for(int e=first[x];e;e=Next[e])
    23         if(v[e]!=fa){
    24             flag=false;
    25             sum=sum+dfs(v[e],x);
    26         }
    27     double re=1-K[x]-E[x];
    28     if(flag)ans.a=K[x],ans.b=ans.c=re,ans.d=1;
    29     else{
    30         double p=1-re*sum.b/sum.d;
    31         ans.a=(K[x]+re*sum.a/sum.d)/p;
    32         ans.b=re/sum.d/p;
    33         ans.c=(re*sum.c/sum.d+re)/p;
    34         ans.d=1;
    35     }
    36     return ans;
    37 }
    38 bool eq(double x,double y){
    39     return fabs(x-y)<eps;
    40 }
    41 int main(){
    42     scanf("%d",&T);
    43     while(T--){
    44         scanf("%d",&n);
    45         cnt=0,memset(first,0,sizeof(first));
    46         int a,b;
    47         for(int i=1;i<n;i++){
    48             scanf("%d%d",&a,&b);
    49             add(a,b),add(b,a);
    50         }
    51         for(int i=1;i<=n;i++){
    52             scanf("%lf%lf",&K[i],&E[i]);
    53             K[i]/=100,E[i]/=100;
    54         }
    55         Xi ans=dfs(1,0);
    56         printf("Case %d: ",++Case);
    57         if(eq(ans.a,1))puts("impossible");
    58         else printf("%.6lf
    ",ans.c/(1-ans.a));
    59     }
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    利用python将表格中的汉字转化为拼音
    vi中批量加注释
    Xtrabackup
    mydumper下载安装
    Adobe Acrobat Pro DC破解
    InnoDB关键特性之double write
    聚集索引与非聚集索引
    has the wrong structure
    初学者如何理解网络协议
    电脑重装系统之后,删除之前的系统
  • 原文地址:https://www.cnblogs.com/Ngshily/p/5526634.html
Copyright © 2011-2022 走看看