2015华农校赛B

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.

输入样例

1
2 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                     10000000000000000


int 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值