tjut 3559

来源:互联网 发布:程序员对公司的建议 编辑:程序博客网 时间:2024/06/05 18:19
#include<iostream>  #include<stdio.h>  #include<stdlib.h>  #include<string.h>  #include<math.h>  #include<vector>  #include<map>  #include<set>  #include<queue>  #include<stack>  #include<string>  #include<algorithm>  using namespace std;  typedef long long ll;  #define inf 99999999  #define maxn 150  struct node{      int x,y;  }a[10];    int g[10][10];  int n,m;  double dp[5][26][6][6][6][6][6][6];  double ans[5];  int cas;      void init()  {      int i,j;      for(i=0;i<5;i++){          for(j=0;j<5;j++){              if((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y)<=m*m  )g[i][j]=1;              else g[i][j]=0;          }      }  }    void dfs(int pos,int shengyu,int t[],double p)  {      int i,j;      if(dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][5]==cas){          for(i=0;i<5;i++){              ans[i]+=dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]*p;          }          return;      }      if(shengyu==0){          for(i=0;i<5;i++){              if(t[i]==0){                  dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=1;                  ans[i]+=p;              }              else{                  dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=0;              }          }          dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][5]=cas;          return;      }      int cnt=0;      for(i=0;i<5;i++){          if(pos!=i && t[i] && g[pos][i])cnt++;      }      if(cnt==0){          for(i=0;i<5;i++){              if(t[i]==0){                  dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=1;                  ans[i]+=p;              }              else{                  dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=0;              }          }          dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][5]=cas;          return;      }      double c[10];      for(i=0;i<5;i++)c[i]=ans[i];      for(i=0;i<5;i++){          if(i!=pos && t[i] && g[pos][i]){              t[i]--;              dfs(i,shengyu-1,t,p/(cnt*1.0) );              t[i]++;          }      }      dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][5]=cas;      for(i=0;i<5;i++)dp[pos][shengyu][t[0] ][t[1] ][t[2] ][t[3] ][t[4] ][i]=(ans[i]-c[i])/p;  }        int main()  {      int i,j,k,t,h,kk,qq,q;      int b[10];      cas=0;      while(scanf("%d%d",&n,&m)!=EOF)      {          memset(ans,0,sizeof(ans));          cas++;          for(i=0;i<5;i++){              scanf("%d%d",&a[i].x,&a[i].y);          }          for(i=0;i<5;i++){              scanf("%d",&b[i]);          }          init();          for(i=0;i<5;i++){              b[i]--;              dfs(i,n,b,0.2);              b[i]++;          }          printf("%.3f %.3f %.3f %.3f %.3f\n",ans[0],ans[1],ans[2],ans[3],ans[4]);      }      return 0;  } 

0 0
原创粉丝点击