Codevs P1652 淘汰賽制
題目描述 Description
淘汰賽制是一種極其殘酷的比賽制度。2n名選手分別標號1,2,3,…2n-1,2n,他們將要參加n輪的激烈角逐。每一輪中,將所有參加該輪的選手按標號從小到大排序後,第1位與第2位比賽,第3位與第4位比賽,第5位與第6位比賽……只有每場比賽的勝者纔有機會參加下一輪的比賽(不會有平局)。這樣,每輪將淘汰一半的選手。n輪過後,只剩下一名選手,該選手即爲最終的冠軍。
現在已知每位選手分別與其他選手比賽獲勝的概率,請你預測一下誰奪冠的概率最大。
輸入輸出 Input&Output
輸入描述 Input Description
輸入文件elimination.in。第一行是一個整數n(1≤n≤10),表示總輪數。接下來2n行,每行2n個整數,第i行第j個是Pij0≤Pij≤100,Pii=0,Pij+Pji=100),表示第i號選手與第j號選手比賽獲勝的概率。
輸出描述 Output Description
輸出文件elimination.out。只有一個整數c,表示奪冠概率最大的選手編號(若有多位選手,輸出編號最小者)。
樣例 Sample
樣例輸入 Sample Input
2
0 90 50 50
10 0 10 10
50 90 0 50
50 90 50 0
樣例輸出 Sample Output
1
數據範圍及提示 Data Size & Hint
[數據規模]
30%的數據滿足n≤3;
100%的數據滿足n≤10。
分析
因爲兩兩之間打,所以二分,先遞歸到第一輪,然後再逐層返回,這樣就先計算出了一開始的概率,而從中間向兩邊的人都有可能打,一側則沒有可能,因爲一側的人早在上一輪就已經打過。
代碼如下
program p1652;
var n,i,j,k,ans:longint;
p:array[1..1024,1..1024] of extended;
f:array[0..10,1..1024] of extended;
procedure dfs(l,r,k:longint);
var i,j,mid:longint;
begin
if k=0
then
begin
exit;
end;
mid:=(l+r)>>1;
dfs(l,mid,k-1);
dfs(mid+1,r,k-1);
for i:=l to mid do
for j:=mid+1 to r do
begin
f[k,i]:=f[k,i]+f[k-1,i]*f[k-1,j]*p[i,j];
f[k,j]:=f[k,j]+f[k-1,j]*f[k-1,i]*p[j,i];
end;
end;
begin
readln(n);
for i:=1 to 1<<n do
for j:=1 to 1<<n do
begin
read(p[i,j]);
p[i,j]:=p[i,j]/100;
end;
fillchar(f,sizeof(f),0);
for i:=1 to 1<<n do f[0,i]:=1;
dfs(1,1<<n,n);
ans:=1;
for i:=2 to 1<<n do
begin
if f[n,i]>f[n,ans]
then ans:=i;
end;
write(ans);
end.
評測結果
運行結果
測試點#elimination1.in 結果:AC 內存使用量: 368kB 時間使用量: 0ms
測試點#elimination10.in 結果:AC 內存使用量: 10604kB 時間使用量: 142ms
測試點#elimination2.in 結果:AC 內存使用量: 368kB 時間使用量: 0ms
測試點#elimination3.in 結果:AC 內存使用量: 368kB 時間使用量: 0ms
測試點#elimination4.in 結果:AC 內存使用量: 368kB 時間使用量: 0ms
測試點#elimination5.in 結果:AC 內存使用量: 492kB 時間使用量: 1ms
測試點#elimination6.in 結果:AC 內存使用量: 496kB 時間使用量: 1ms
測試點#elimination7.in 結果:AC 內存使用量: 1004kB 時間使用量: 1ms
測試點#elimination8.in 結果:AC 內存使用量: 1900kB 時間使用量: 8ms
測試點#elimination9.in 結果:AC 內存使用量: 4460kB 時間使用量: 34ms
不知道寫啥。。。
擔心。。。。╮(╯▽╰)╭。。。
past
Holy Ground
Taylor Swift
I was reminiscing just the other day
While having coffee all alone and Lord, it took me away
Back to a first-glance feeling on New York time
Back when you fit in my poems like a perfect rhyme
Took off faster than a green light “Go”
Yeah, skipped the conversation when you already know
I left a note on the door with a joke we’d made
And that was the first day
And darling, it was good never looking down
And right there where we stood was Holy Ground
Spinning like a girl in a brand new dress
We had this big wide city all to ourselves
We blocked the noise with the sound of ‘I need you’
And for the first time I had something to lose
And I guess we fell apart in the usual way
And the story’s got dust on every page
But sometimes I wonder how you think about it now
And I see your face in every crowd
Cause darling, it was good never looking down
And right there where we stood was Holy Ground
Tonight I’m gonna dance for all that we’ve been through
But I don’t wanna dance if I’m not dancing with you
Tonight I’m gonna dance like you were in this room
But I don’t wanna dance if I’m not dancing with you
It was good never looking down
And right there where we stood was Holy Ground
Tonight I’m gonna dance for all that we’ve been through
But I don’t wanna dance if I’m not dancing with you
Tonight I’m gonna dance like you were in this room
But I don’t wanna dance if I’m not dancing with you