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
- 2015华农校赛B
- 华农校赛warmup1
- 华农校赛E题
- 简单模拟——拥挤的华农校巴
- HDU 5528【2015长春现场赛 B】 Count a * b
- 2015 四川省赛 B. Carries
- hdu5438(2015长春网络赛B题)
- hihoCoder1228(2015北京网络赛B题)
- 2015 四川省赛 B Carries (脑洞题)
- 第一次周赛B
- JNOJ揭幕赛-B
- [SCOI 2015集训]B
- Good Bye 2015B
- b
- b
- b
- //b
- B
- mySql获取从第A条到第B条数据
- Linux Command - source
- 【c语言】实现一个通讯录
- Spring基础
- 再探MFC(八)使用数据库
- 2015华农校赛B
- 写下你职业生涯中最难以忘怀的误操作。。
- POJ-2653
- 异或的性质及运用
- 设计模式 笔记 原型模式 prototype
- C++ 大规模程序设计 之 全局名称空间
- SpringMVC基础
- ubuntu 用iso 文件制作u 盘启动工具命令
- 第五周项目1-体验常成员函数