3个OSU【期望】

by luogu

 

期望dp

 

 

WJMZBMR打osu! / Easy

很好的题,但是我太菜了

我开始的思路是统计?的个数,然后dfs处理

 但是发现N3e5我的想法也无法实现

 

len记录当前一连串 o 的个数

当遇到 x 时处理结束;

 

 

#include<bits/stdc++.h>

using namespace std;
const int N=3e5+7; 

int n;
long double dp[N],len;
//注意精度问题
//dp[i]->前 i的期望 
string a;

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>a;
    for(int i=1;i<=n;i++)
    {
        
        if(a[i-1]=='?')
            {
                dp[i]=dp[i-1]+len+0.5;
                len=(len+1)/2;
            }
        else if(a[i-1]=='o')
            {
                dp[i]=dp[i-1]+(len*2)+1;
                len++;
            }
        else if(a[i-1]=='x')
            {
                dp[i]=dp[i-1];
                len=0;
            }
            
    }

    
    printf("%.4Lf",dp[n]);
    return 0;
 } 

 

OSU!

 

#include<bits/stdc++.h>

using namespace std;
const int N=1e5+7;

int n;
double x_2[N] ,x[N];
double a;
double  dp[N];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;    
    
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        x[i]=(x[i-1]+1)*a;
        x_2[i]=(x_2[i-1]+2*x[i-1]+1)*a;
        
        dp[i]=dp[i-1]+(3*(x[i-1]+x_2[i-1])+1)*a;
    }
    printf("%.1f\n",dp[n]);
    return 0;
}

 

 

CF235B Let's Play Osu!

 

#include<bits/stdc++.h>

using namespace std;

const int N=1e5+7;

int n;
double x[N];
double a;
double dp[N];


int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        x[i]=(x[i-1]+1)*a;
        
        dp[i]=dp[i-1]+(2*x[i-1]+1)*a;
    }
    
    printf("%.6f\n",dp[n]);
    return 0;
}

 

posted @ 2021-09-13 20:23  Hehe_0  阅读(58)  评论(0)    收藏  举报