osu!三连击

P1654 OSU!

题目背景

原 《产品排序》 参见P2577

题目描述

osu 是一款群众喜闻乐见的休闲软件。

我们可以把osu的规则简化与改编成以下的样子:

一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1个长度为n的01串。在这个串中连续的 个1可以贡献 的分数,这x个1不能被其他连续的1所包含(也就是极长的一串1,具体见样例解释)

现在给出n,以及每个操作的成功率,请你输出期望分数,输出四舍五入后保留1位小数。

输入输出格式

输入格式:

第一行有一个正整数n,表示操作个数。接下去n行每行有一个[0,1]之间的实数,表示每个操作的成功率。

输出格式:

只有一个实数,表示答案。答案四舍五入后保留1位小数。

输入输出样例

输入样例#1: 
3 
0.5 
0.5 
0.5
输出样例#1: 
6.0

说明

【样例说明】

000分数为0,001分数为1,010分数为1,100分数为1,101分数为2,110分数为8,011分数为8,111分数为27,总和为48,期望为48/8=6.0

N<=100000

code

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int n;
double p[100010], t[100010], f[100010];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++ i) {
        double x; cin >> x;
        p[i] = (p[i - 1] + 1) * x;
        t[i] = (t[i - 1] + p[i - 1] * 2 + 1) * x;
        f[i] = f[i - 1] + (3 * t[i - 1] + 3 * p[i - 1] + 1) * x;
    }
    printf("%.1lf\n", f[n]);
    return 0;
} 

A掉之后,突发奇想在洛谷上搜了一下osu。发现还有两道题,也是打osu,也是期望……然后就顺便把另两个也A了

P1365 WJMZBMR打osu! / Easy

题目背景

原 维护队列 参见P1903

题目描述

某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(

我们来简化一下这个游戏的规则

nnn 次点击要做,成功了就是o,失败了就是x,分数是按combo计算的,连续 aaa 个combo就有 a×aa\times aa×a 分,combo就是极大的连续o

比如ooxxxxooooxxx,分数就是 2×2+4×4=4+16=202 \times 2 + 4 \times 4 = 4 +16=202×2+4×4=4+16=20 。

Sevenkplus闲的慌就看他打了一盘,有些地方跟运气无关要么是o要么是x,有些地方o或者x各有50%的可能性,用?号来表示。

比如oo?xx就是一个可能的输入。 那么WJMZBMR这场osu的期望得分是多少呢?

比如oo?xx的话,?o的话就是oooxx => 9,是x的话就是ooxxx => 4

期望自然就是 (4+9)/2=6.5(4+9)/2 =6.5(4+9)/2=6.5 了

输入输出格式

输入格式:

第一行一个整数 nnn ,表示点击的个数

接下来一个字符串,每个字符都是o,x,?中的一个

输出格式:

一行一个浮点数表示答案

四舍五入到小数点后 444 位

如果害怕精度跪建议用long double或者extended

输入输出样例

输入样例#1: 
4
????
输出样例#1: 
4.1250

说明

osu很好玩的哦

WJMZBMR技术还行(雾),x基本上很少呢

code

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 300010;
int n;
char osu[MAXN];
double ans;

//o,x,?
int main() {
    double combo = 0.0;
    scanf("%d%s", &n, osu + 1);
    for (int i = 1; i <= n; ++ i) {
        if (osu[i] == 'o') {
            ans += (combo * 2.0 + 1.0);
            combo++;
        }
        else if (osu[i] == 'x') combo = 0;
        else {
            ans += (combo + 0.5);
            combo = (combo + 1) / 2;
        }
    }
    printf("%.4lf\n", ans);
    return 0;
}

CF235B Let's Play Osu!

题意翻译

你在玩一个叫做Osu的游戏(某音游)!我们来简化一下游戏规则。一局游戏中需要点击n次。每一次点击有两种结果:正确或失误。我们定义正确为符号"O",失误为"X",那么整局游戏可以被写成一个长度为n的由字符"X"或"O"组成的字符串。

用这个字符串你可以用以下的方法计算游戏的得分:对于一个极大的连续的"O"连击,将连击的次数的平方加入到总得分中(即连续的"O"的个数的平方)。举例说明,如果你的游戏序列为"OOXOOOXXOO",那么极大连续的“O”连击共有三个:"OO","OOO","OO",所以你的总得分为 2^2 + 3^2 + 2^2= 17 。如果整局游戏里没有一次成功的点击那么总得分就为 0 。

你现在知道了第i次( 1<=i<=n )点击成功的概率为 p_i,换句话说,字符串中第i个字符有 p_i 的概率成为"O",有 1-p_i 的概率成为"X",你的任务是算出你游戏总得分的期望值。

输入输出格式 输入格式: 第一行包含一个整数表示点击的次数 n ( 1<=n<=10^5 ) 第二行包含 n 个由空格间隔开的实数p_1,p_2,...,p_n ( 0<=p_i<=1 ) 输入的 p_i 最多为六位小数

输出格式: 输出一个实数——你游戏的期望得分。你的答案必须与标准答案的误差不超过 10^{-6}

样例一说明 3位字符串一共有8种不同的情况。每一种出现的概率为0.125 所以期望得分是 (9+4+2+1+4+1+1)/8=2.75

感谢@凄魉 提供的翻译

题目描述

You're playing a game called Osu! Here's a simplified version of it. There are n n n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of n n n characters "O" and "X".

Using the play sequence you can calculate the score for the play as follows: for every maximal consecutive "O"s block, add the square of its length (the number of characters "O") to the score. For example, if your play can be encoded as "OOXOOOXXOO", then there's three maximal consecutive "O"s block "OO", "OOO", "OO", so your score will be 22+32+22=17 2^{2}+3^{2}+2^{2}=17 22+32+22=17 . If there are no correct clicks in a play then the score for the play equals to 0 0 0 .

You know that the probability to click the i i i -th (1<=i<=n) (1<=i<=n) (1<=i<=n) click correctly is pi p_{i} pi . In other words, the i i i -th character in the play sequence has pi p_{i} pi probability to be "O", 1−pi 1-p_{i} 1pi to be "X". You task is to calculate the expected score for your play.

输入输出格式

输入格式:

The first line contains an integer n n n ( 1<=n<=105 1<=n<=10^{5} 1<=n<=105 ) — the number of clicks. The second line contains n n n space-separated real numbers p1,p2,...,pn p_{1},p_{2},...,p_{n} p1,p2,...,pn (0<=pi<=1) (0<=p_{i}<=1) (0<=pi<=1) .

There will be at most six digits after the decimal point in the given pi p_{i} pi .

输出格式:

Print a single real number — the expected score for your play. Your answer will be considered correct if its absolute or relative error does not exceed 10−6 10^{-6} 106 .

输入输出样例

输入样例#1: 
3
0.5 0.5 0.5
输出样例#1: 
2.750000000000000
输入样例#2: 
4
0.7 0.2 0.1 0.9
输出样例#2: 
2.489200000000000
输入样例#3: 
5
1 1 1 1 1
输出样例#3: 
25.000000000000000

说明

For the first example. There are 8 possible outcomes. Each has a probability of 0.125.

  • "OOO" → → 32=9 3^{2}=9 32=9 ;
  • "OOX" → → 22=4 2^{2}=4 22=4 ;
  • "OXO" → → 12+12=2 1^{2}+1^{2}=2 12+12=2 ;
  • "OXX" → → 12=1 1^{2}=1 12=1 ;
  • "XOO" → → 22=4 2^{2}=4 22=4 ;
  • "XOX" → → 12=1 1^{2}=1 12=1 ;
  • "XXO" → → 12=1 1^{2}=1 12=1 ;
  • "XXX" → → 0 0 0 .

So the expected score is

code

#include <cstdio>
 
int main() {
    int n;
    scanf("%d", &n);
    double ans = 0, p = 0, combo = 0;
    while(n --) {
        scanf("%lf", &p);
        combo *= p;
        ans += 2 * combo + p;
        combo += p;
    }
    printf("%.10f\n", ans);
}

luogu期望评分难度都这么高的吗QWQ

题目好像格式有点问题……凑合着看吧

猜你喜欢

转载自www.cnblogs.com/hkttg/p/9382563.html