概率與期望
https://vjudge.net/problem/LightOJ-1030
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
int t;
cin>>t;
int a[110];
double dp[110];
for(int i=1;i<=t;i++)
{
memset(a,0,sizeof(a));
memset(dp,0,sizeof(dp));
dp[1]=1;
int n,h;
double ans=0;
cin>>n;
for(int j=1;j<=n;j++)
cin>>a[j];
for(int j=1;j<=n;j++){
if(n-j<6)
h=n-j;
else
h=6;
for(int k=1;k<=h;k++)
{
dp[j+k]+=dp[j]*1.0*1/h;
}
ans+=1.0*a[j]*dp[j];
}
printf("Case %d: %lf\n",i,ans);
}
return 0;
}
https://vjudge.net/problem/LightOJ-1027
#include<iostream>
using namespace std;
int gcd(int a,int b)
{
return b>0?gcd(b,a%b):a;
}
int main()
{
int t;
int a[110];
cin>>t;
for(int i=1;i<=t;i++)
{
int n,sum1=0,sum2=0,door1=0,door2=0;
cin>>n;
for(int j=0;j<n;j++)
{
cin>>a[j];
if(a[j]>0)
{
sum1+=a[j];
door1++;
}
else
{
sum2+=-a[j];
door2++;
}
}
int q=gcd(sum1+sum2,n-door2);
cout<<"Case "<<i<<‘:‘<<‘ ‘;
if(door2==n)
cout<<"inf"<<endl;
else
cout<<(sum1+sum2)/q<<‘/‘<<(n-door2)/q<<endl;
}
return 0;
}
概率與期望
相關推薦
poj 3744 Scout (Another) YYF I - 概率與期望 - 動態規劃 - 矩陣快速冪
遞推 cto bits dig min ability 構建 nes text (Another) YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate int
Discovering Gold LightOJ - 1030 || 概率與期望求法區別
targe cas get amp %d 通過 sum -i lightoj 1 #include<cstdio>//wrong_codes 2 #include<algorithm> 3 using namespace std;
BZOJ 1426--收集郵票(概率與期望&DP)
不同 include online 沒有 收集 pass main 數字 bzoj 1426: 收集郵票 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 504 Solved: 417[Submit][Status][D
【BZOJ3470】Freda’s Walk 概率與期望
space 現在 pre -c 我們 mil pop 小數 ble 【BZOJ3470】Freda’s Walk Description 雨後的Poetic Island空氣格外清新,於是Freda和Rainbow出來散步。 Poetic Island的
Codeforces 866C Gotta Go Fast - 動態規劃 - 概率與期望 - 二分答案
you div 圖片 cin decision dot contains take als You‘re trying to set the record on your favorite video game. The game consists
概率與期望DP習題總結
tin pos thead 生成 相減 new 單選 str 狀壓 部分資料從[GuessYCB][1]搬運過來 施工中~ 以下並非嚴格分類,部分題目需要幾種方法混用 題型 題目
學習筆記--概率與期望
推廣 可能 試驗 同時 導致 取出 集合 .com strong 相關概念 基本事件ω(也稱樣本點): 一次試驗可能出現的每一個直接的 結果。也就是隨機試驗不能夠再分解的結果。 如:E1有兩個基本事件:E1 ={出現正面}, E2={出現反面} E2有六個基本事件
【算法總結】概率與期望相關
else tle 選擇 def mem html ros 也不能 algorithm 〖相關資料〗 《淺析競賽中一類數學期望問題的解決方法》 〖相關題目〗 1.【bzoj1415】[NOI2005] 聰聰和可可 題意:在一個魔法森林裏,住著一只聰明的小貓聰聰和一只可
概率與期望
-a names AI return str sizeof 概率 lightoj end https://vjudge.net/problem/LightOJ-1030 #include<iostream>#include<stdio.h>#incl
lightoj1038(數學概率與期望)
每次 iostream ios 輸入一個數 esp pac lightoj size fin 題意:輸入一個數N,N每次被它的任意一個因數所除 變成新的N 這樣一直除下去 直到 N變為1 求變成1所期望的次數 解析: d[i] 代表從i除到1的期望步數;那麽假設i一共有c個
[BJWC2011]禁忌 AC 自動機 概率與期望
algo char push highlight set 期望 printf lse queue #include<cstdio> #include<algorithm> #include<cstring> #include<st
【概率與期望】【組合計數】TopCoder SRM 561 Orienteering
題意: 給出一顆樹,樹上有些選中點 C C C,現在隨機從中選擇一個大小為
【概率與期望】AGC019 F Yes or No
分析: 首先,很容易搞出來一個N^2的DP做法,顯然會T,但是對發現正解有很大幫助: 將這個DP轉換為一個網格,就變為:從起始點(n,m)出發,到達目標點(0,0)的期望路徑長度。 首先,有一個很厲害的結論:因為每次都是按照最優策略選答案,所以不妨設n>=m,那麼一定能答對
數論-概率與期望
數論 中位數 info lin 試驗 眾數 公式 分享圖片 事件 補一波筆記 概率與期望 概率類型 古典概型 特點:時間互相排斥、可能性相等 計算公式: 幾何概型 計算公式: 概率計算性質 事件發
【DP】【概率與期望】2018國慶三校聯考D3T2
題意: 分析: #include<cstdio> #include<cstring> #include<algorithm> #include<cma
bzoj 4770 圖樣 - 概率與期望 - 動態規劃
題目傳送門 傳送門I 傳送門II 題目大意 有一個$n$個點的完全圖,每個點的權值是$[0, 2^{m})$中的隨機整數,兩點間的邊的權值是兩點點權的異或和,問它的最小異或生成樹的邊權和的期望。 考慮求最大異或生成樹的分治做法,每次按最高位分成$V_0,V_1$
[JZOJ5978] 排列【計數】【排列組合】【概率與期望】
Description n<=5000,a[i]<=n,也就是說原序列是個排列 Solution 觀察定義式,感覺很像什麼隨機點分治的期望複雜度 如果弄出原序列,建出笛卡爾樹,那麼函式值就是笛卡爾樹每個節點的子樹大小和。 接下來就是套路了 考慮計算任意一對下
【雜題】[LibreOJ 2541] 【PKUWC2018】獵人殺【生成函式】【概率與期望】
Description 獵人殺是一款風靡一時的遊戲“狼人殺”的民間版本,他的規則是這樣的: 一開始有 n個獵人,第 i 個獵人有仇恨度 wi。每個獵人只有一個固定的技能:死亡後必須開一槍,且被射中的人也會死亡。 然而向誰開槍也是有講究的,假設當前還活著的獵人有
bzoj3451: Tyvj1953 Normal點分治+FFT 概率與期望
bzoj3451: Tyvj1953 Normal 題目傳送門 分析 求隨機寫的點分治複雜度期望。 這類題有一個套路:考慮兩個點的貢獻。 如果說一個點 x
bzoj1076(概率與期望dp入門)
題目大意:給定k次彈出寶物的機會,每次隨機彈出n種寶物的機會,如果吃過這種寶物的所有前提寶物就可以吃這種寶物,求最優策略的期望得分 看到資料範圍果斷狀壓DP- - 不看資料範圍害死人- - 至於吃還是不吃 這是個問題 對於這種最優策略的期望DP 我們一般都是從後往前推 列舉