hdu4418 Time travel

网友投稿 700 2022-08-29

hdu4418 Time travel

hdu4418 Time travel

​​ Problem Description

Agent K is one of the greatest agents in a secret organization called Men in Black. Once he needs to finish a mission by traveling through time with the Time machine. The Time machine can take agent K to some point (0 to n-1) on the timeline and when he gets to the end of the time line he will come back (For example, there are 4 time points, agent K will go in this way 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, …). But when agent K gets into the Time machine he finds it has broken, which make the Time machine can’t stop (Damn it!). Fortunately, the time machine may get recovery and stop for a few minutes when agent K arrives at a time point, if the time point he just arrive is his destination, he’ll go and finish his mission, or the Time machine will break again. The Time machine has probability Pk% to recover after passing k time points and k can be no more than M. We guarantee the sum of Pk is 100 (Sum(Pk) (1 <= k <= M)==100). Now we know agent K will appear at the point X(D is the direction of the Time machine: 0 represents going from the start of the timeline to the end, on the contrary 1 represents going from the end. If x is the start or the end point of the time line D will be -1. Agent K want to know the expectation of the amount of the time point he need to pass before he arrive at the point Y to finish his mission. If finishing his mission is impossible output “Impossible !” (no quotes )instead.

Input There is an integer T (T <= 20) indicating the cases you have to solve. The first line of each test case are five integers N, M, Y, X .D (0< N,M <= 100, 0 <=X ,Y < 100 ). The following M non-negative integers represent Pk in percentile.

Output For each possible scenario, output a floating number with 2 digits after decimal point If finishing his mission is impossible output one line “Impossible !” (no quotes )instead.

Sample Input 2 4 2 0 1 0 50 50 4 1 0 2 1 100

Sample Output 8.14 2.00 题面很毒瘤 钦定一个起点 询问 走到终点需要经过的点数的期望值是多少 由于这是一个环的形式且两个方向所以我们把它展开 然后这样方向就唯一了 那设dp[i]表示从i到终点经过点的期望 首先bfs 确定哪些点从起点并不能走到 然后列方程的时候注意给inf 即可 方程就很简单了dp[x]=sigma(i=1,i<=m) (dp[(x+i)%n]+i)*p[i] 然后把常数项提出来即可

#include#include#include#include#include#include#define eps 1e-9using namespace std;inline char gc(){ static char now[1<<16],*S,*T; if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;} return *S++;}inline int read(){ int x=0,f=1;char ch=gc(); while(!isdigit(ch)) {if (ch=='-') f=-1;ch=gc();} while(isdigit(ch)) x=x*10+ch-'0',ch=gc(); return x*f;}const int N=220;bool visit[N];int T,n,m,t,s,d;double p[N],a[N][N],sum,ans[N];inline void bfs(){ queueq;q.push(s);memset(visit,0,sizeof(visit));visit[s]=1; while(!q.empty()){ int x=q.front();q.pop(); for (int i=1;i<=m;++i) { int to=x+i;to%=n;if (visit[to])continue; if (fabs(p[i])

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:权限管理(RBAC),不会的了解一下
下一篇:PHP验证码生成原理和实现
相关文章

 发表评论

暂时没有评论,来抢沙发吧~