# HDU 3559 Frost Chain

2 篇文章 0 订阅
1 篇文章 0 订阅

## Frost Chain

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 495    Accepted Submission(s): 214

Problem Description
In the unimaginable popular DotA game, the hero Lich has a wonderful skill: Frost Chain, release a jumping breath of frost that jumps N times against enemy units.

Today iSea play the role of Lich, at first he randomly chooses an enemy hero to release the skill, then the frost jumps for N times. Each time, it make a damage of one HP unit on this hero (including the first time), then bounces to another hero (can’t be himself) if their distance is no more than D and this hero is alive of course, also randomly. Here random means equal probability.

Now we know there are always only five enemy heroes, and also their coordinates and HP value. iSea wonders the death probability of each hero. One hero is dead if its HP is equal to or less than zero.

Input
There are several test cases in the input.

Each test case begin with two integers N and D (1 <= N <= 25, 1 <= D <= 10000).
The following line contains ten integers, indicating the coordinates of the five opponents, and -10000 ≤ x, y ≤ 10000.
Then five integers follows, indicating the HP (1 <= HP <= 5) of five opponents.

The input terminates by end of file marker.

Output
For each test case, output five floating numbers, indicating the death probability of each hero, as the given order, rounded to three fractional digits, and separated by a single blank.

Sample Input


3 100
0 1 0 2 0 3 0 4 0 5
1 1 1 1 1
3 1
0 1 0 2 0 3 0 4 0 5
1 1 1 1 1



Sample Output


0.800 0.800 0.800 0.800 0.800
0.500 0.800 0.800 0.800 0.500



#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int n,status;
bool gap[7][7];//记录两点之间是否能够到达
double dp[7][30][1<<15];
/*
dp[i][j][k]第j次造成伤害，停留在i上，状态为k的概率
*/
double D;
int QK[7*30*(1<<15)],QS[7*30*(1<<15)],QL[7*30*(1<<15)];
/*

*/
bool vis[7][30][1<<15];
const int M[5]={28672,3584,448,56,7};
/*

*/
const int De[5]={4096,512,64,8,1};
/*

*/
double ans[5];

struct coor
{
double x;
double y;
}hero[5];

double dis(coor a,coor b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int num(int s,int h)//用于计算在状态s时，除了h以外存活的英雄的数量
{
int cnt=0;
for(int i=0;i<5;i++)
if(gap[h][i]&&(s&M[i]))
cnt++;
return cnt;
}
void bfs()
{
QK[0]=0;
QS[0]=status;
QL[0]=6;
dp[6][0][status]=1.0;
{
if(k==n+1)
continue;
if(vis[last][k][s])
continue;
vis[last][k][s]=true;
for(int i=0;i<5;i++)
{
int nh=num(s,last);
if(nh&&(s&M[i])&&gap[i][last])
{
double t=dp[last][k][s]/(nh*1.0);
dp[i][k+1][s-De[i]]+=t;
if(!((s-De[i])&M[i]))
ans[i]+=t;
if(vis[i][k+1][s-De[i]])
continue;
QK[tail]=k+1;
QS[tail]=s-De[i];
QL[tail]=i;
tail++;
}
}
}
for(int i=0;i<tail;i++)
{
int k=QK[i],s=QS[i],last=QL[i];
vis[last][k][s]=false;
dp[last][k][s]=false;
}
/*
注意这里两个case之间不能用memset,不然会TLE，原因是你BFS的过程中有许多状态没有用到
*/
}

int main()
{
memset(dp,0,sizeof dp);
memset(vis,0,sizeof vis);
while(scanf("%d%lf",&n,&D)!=EOF)
{
memset(gap,0,sizeof gap);
for(int i=0;i<5;i++)
{
double x,y;
scanf("%lf%lf",&x,&y);
hero[i].x=x;
hero[i].y=y;
}
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
{
if(i==j)
continue;
if(dis(hero[i],hero[j])<=D)
gap[i][j]=true;
}
status=0;
for(int i=0;i<5;i++)
{
status<<=3;
int hp;
scanf("%d",&hp);
status+=hp;
}
for(int i=0;i<=6;i++)//假设一个结点6能够连通所有的结点
gap[i][6]=gap[6][i]=true;
for(int i=0;i<5;i++)
dp[i][0][status]=1.0;
memset(ans,0,sizeof ans);
bfs();
for(int i=0;i<4;i++)
printf("%.3f ",ans[i]);
printf("%.3f\n",ans[4]);
}
return 0;
}     

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
08-21 673
09-28 442
12-03 1932
07-22 969
01-27 1903
02-04 1126
07-11

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。