hdu 4576——Robot

来源:互联网 发布:新闻自动生成软件 编辑:IT博客网 时间:2019/09/17 14:18

 

 

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<cstdlib>#include<map>#include<set>#include<string>#include<cctype>#include<vector>#include<queue>using namespace std;double dp[210],a[210];int main(){int n,m,l,r;int k;int step;while(~scanf("%d%d%d%d",&n,&m,&l,&r)&&n+m+l+r){memset(a,0,sizeof(a));memset(dp,0,sizeof(dp));a[1]=1;while(m--){scanf("%d",&k);if(k<0)k=n-k;for(int i=1;i<=n;i++)if(a[i]!=0.0){step=(k+i)%n;if(step==0)step=n;dp[step]+=a[i]*0.5;step=(i-k+200*n)%n;if(step==0)step=n;dp[step]+=a[i]*0.5;}memcpy(a,dp,sizeof(a));memset(dp,0,sizeof(dp));}double ans=0.0;for(int i=l;i<=r;i++)ans+=a[i];printf("%.4f\n",ans);}return 0;} 


 

原创粉丝点击