1. 程式人生 > >osu!三連擊

osu!三連擊

set long bottom code note ... 兩個 沒有 個數

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

題目好像格式有點問題……湊合著看吧

osu!三連擊