Codevs P1652 淘汰赛制

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

发布了76 篇原创文章 · 获赞 0 · 访问量 4万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章