2015华农校赛B

来源:互联网 发布:淘宝标题怎么写吸引人 编辑:程序博客网 时间:2024/06/10 08:33

B  Tower

Time Limit:1000MS  Memory Limit:65535K

题型: 编程题   语言: 无限制

描述

There is a tower, which have n+1 floors, numbered from 0 to n. Each floor have m distinct doors, one of them is true while others not. The true door can take you to floor i+1 when you in floor i. The false one will take you to floor max(i-1, 0) when you in floor I, suffer one damage at the same time. Entering each door will take a unit of time. Someone wants to go to floor n from the floor 0, and he doesn’t know which door is true at first. He will remember the door he went before. Here comes the question, what’s the expectation of the damage he will suffer and the time he will take. 

输入格式

First line is a integer T, the number of case. Every case have two integers n, m.(0 <= n <= 10000000, 0 < m <= 10000000)

输出格式

Output the expectation of the damage he will suffer and the time he will take, accurate to two digits after the decimal point.

输入样例

12 2

输出样例

1.00 3.50

Hint

All possibilities in sample:(t means go into the true door, f means go into the false door)0(f) -> 0(t) -> 1(f) -> 0(t) -> 1(t) -> 2 (damage 2,time 5)0(f) -> 0(t) -> 1(t) -> 2 (damage 1,time 3)0(t) -> 1(f) -> 0(t) -> 1(t) -> 2 (damage 1,time 4)0(t) -> 1(t) -> 2 (damage 0,time 2)

So the expectation of the damage he will suffer is(2+1+1+0)/4 = 1.00,the expectation of the time he will take is(5+3+4+2)/4 = 3.50.

题意:从0层上到n+1层,每层有n扇门,其中只有一扇门是正确的,每开一道门花费一个单位时间,如果正确则上一层,如果错误则下一层并且守一次伤害,0层就不可以在掉。

而且走过的门可以记住。求n+1层,每层m扇门,从0到n+1层需要的时间的期望和收到的伤害的期望。

思路:因为走过的门可以记住,所以如果掉了一层下一次可以马上上去。

对于时间:

如果是第0层:Tm=1/m+(m-1)/m*(T(m-1)+1) ====>Tm=(m+1)/2;

对于以上的层:Tm=1/m+(m-1)/m*(T(m-1)+2) ====>Tm=m;

所以:T(n,m)=(m+1)/2+(n-1)m;

对于伤害:

Dm=(m-1)/m(D(m-1)+1) =====>Dm=(m-1)/2

所以D(n,m)=n*(m-1)/2;

#include <iostream>#include <cmath>#include <stdio.h>#include <map>#include <string>#include <string.h>#include <algorithm>#include <queue>using namespace std;#define REP(i,a,b)              for(int i=a;i<b;++i)#define scan(a)                 scanf("%d",&a)#define maxn                    1000005#define mset(a,b)               memset(a,b,sizeof a)#define LL                      long long//#define mod                     10000000000000000int main(){    double m,n;    double T,D;    int t;    cin>>t;    while(t--)    {        scanf("%lf%lf",&n,&m);        if(n<0.1)        {            puts("0.00 0.00");            continue;        }        T=(m+1)/2+(n-1)*m;        D=n*(m-1)/2;        printf("%.2lf %.2lf\n",D,T);    }}



0 0
原创粉丝点击