Duha decided to have a trip to Singapore by plane.

The airplane had nn seats numbered from 11 to nn, and nn passengers including Duha which were also counted from 11 to nn. The passenger with number ii held the ticket corresponding to the seat with number ii, and Duha was the number 11 passenger.

All passengers got on the plane in the order of their numbers from 11 to nn. However, before they got on the plane Duha lost his ticket (and Duha was the only passenger who lost the ticket), so he could not take his seat correctly. He decided to take a seat randomly. And after that, while a passenger got on the plane and found that his/her seat has been occupied, he/she selected an empty seat randomly as well. A passenger except Duha selected the seat displayed in his/her ticket if it had not been occupied by someone else.

The first problem you are asked to calculate in this problem is the probability of the last passenger to get on the plane that took his/her correct seat.

Several days later, Duha finished his travel in Singapore, and he had a great time.

On the way back, he lost his ticket again. And at this time, the airplane had mm seats numbered from 11 to mm, and mm passengers including Duha which were also counted from 11 to mm. The passenger with number ii held the ticket corresponding to the seat with number ii, and Duha was the number 11 passenger as well.

The difference was that: all passengers got on the plane in a random order (which was any one of the mm! different orders with the same chance). Similarly, Duha or a passenger who found his/her seat had been occupied selected an empty seat randomly.

The second problem you are asked to calculate in this problem is the probability of the last passenger to get on the plane that took his/her right seat on the return trip.

Input

The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.

For each test case, a line contains two integers nn and m (1 \le n, m \le 50)m(1≤n,m≤50).

Output

For each test case, output a line containing Case #x: y z, where xx is the test case number starting from 11, yy is the answer of the first problem, and zz is the answer of the second problem. Both of yy and zz are rounded to 66 places, and we guarantee that their 77-th places after the decimal point in the precise answer would not be 44 or 55.

输出时每行末尾的多余空格,不影响答案正确性

样例输入复制

1
2 3

样例输出复制

Case #1: 0.500000 0.666667

这个题,一场比赛下来,有人跑过来跟我说容斥定理,又有什么DFS的,这些全是抄题解,这不就是一个推公式的题目吗?队友推了很久,最后在一群人的指点江山下,自己推出公式;这个题就是一个疯子坐飞机概率问题:https://www.zhihu.com/question/35950050/answer/65272204

先讨论第一问,第一问的话,当这个呆瓜坐下,无论前N-1个怎么做,最后一个上来的人面对的是一个独立问题,是坐对或坐错,我们论证一下:

1、当只有两个人的时候,呆瓜是第一个,他有两种选择,作对坐不对,那么对于最后一个人,也有两种情况,坐对,坐错。

2、当只有三个人的时候,呆瓜是第一个,那么他有三种选择,1,2,3那么他有1/3的几率坐对,而只有他蠢,他坐对了,其他人都坐对了,在考虑其余2/3,那么对于当第一个人做了第二个人的位置,那么第二个人上来之后可以做第一个人的位置,也可以坐第三个人的位置,那么第三个人坐对的概率是1/2,在讨论,当第一个人做了第三个人的位置时,第三个人一定做不到自己的位置上,那么坐对坐不对的情况都是1/3+1/6=1/2。

3、那么当有四个人的时候,他坐在对于他做的四种情况都能推导到比他更低的人数的情况,而对于每种情况都是1/2,

那么第一问的答案永远都是1/2,那么我们考虑第二问,除了这个呆瓜之外,在他之前上来的肯定都坐对了,那么转化为第一种情况,除了一个人的时候是1之外,除了1/2之外还有第三种情况,是呆瓜最后上来,别人都坐对了,那他肯定也做对了,就是1,所以这个题的话就是有1/N的几率呆瓜最后上来,有N-1/N的情况是他在之前上来1/2的情况,那么答案即为 

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define LL long long
#define MAXN 1000100
int main()
{
int t,n,m,p=1;
cin>>t;
while(t--)
{
cin>>n>>m;
cout<<"Case #"<<p++<<": ";
if(n==1)
cout<<"1.000000"<<' ';
else
cout<<"0.500000"<<' ';
cout<<fixed<<setprecision(6)<<(m+1)*1.0/(2*m)<<endl;
}

2019 ICPC 银川网络赛 D. Take Your Seat (疯子坐飞机问题)的更多相关文章

  1. 2019 ICPC 银川网络赛 H. Fight Against Monsters

    It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Eg ...

  2. 2019 ICPC 银川网络赛 F-Moving On (卡Cache)

    Firdaws and Fatinah are living in a country with nn cities, numbered from 11 to nn. Each city has a ...

  3. 2019 ICPC 南昌网络赛

    2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 ...

  4. 2019 ICPC上海网络赛 A 题 Lightning Routing I (动态维护树的直径)

    题目: 给定一棵树, 带边权. 现在有2种操作: 1.修改第i条边的权值. 2.询问u到其他一个任意点的最大距离是多少. 题解: 树的直径可以通过两次 dfs() 的方法求得.换句话说,到任意点最远的 ...

  5. 2019 ICPC 沈阳网络赛 J. Ghh Matin

    Problem Similar to the strange ability of Martin (the hero of Martin Martin), Ghh will random occurr ...

  6. 2019 ICPC 南昌网络赛I:Yukino With Subinterval(CDQ分治)

    Yukino With Subinterval Yukino has an array a_1, a_2 \cdots a_na1,a2⋯*a**n*. As a tsundere girl, Yuk ...

  7. 2019 ICPC南昌网络赛 B题

    英雄灭火问题忽略了一点丫 一个超级源点的事情,需要考虑周全丫 2 #include<cstdio> #include<cstring> #include<queue> ...

  8. 2019 ICPC 徐州网络赛 B.so easy (并查集)

    计蒜客链接:https://nanti.jisuanke.com/t/41384 题目大意:给定n个数,从1到n排列,其中有q次操作,操作(1) 删除一个数字 // 操作(2)求这个数字之后第一个没有 ...

  9. 2019 ICPC徐州网络赛 E. XKC's basketball team(二分)

    计蒜客题目链接:https://nanti.jisuanke.com/t/41387 题目大意:给定一组无序序列,从第一个数开始,求最远比这个数大m的数,与这个数之间相隔多少数字?如果没有输出-1,否 ...

随机推荐

  1. Android AndroidManifest.xml详解

    AndroidManifest.xml简述: AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activitie ...

  2. Jenkins构建项目后发送钉钉消息推送

    前言 钉钉是我们日常工作的沟通工具,在Jenkins构建持续集成项目配合钉钉机器人的功能,可以让我们在持续集成测试环节快速接收到测试结果的消息推送. 一:新建一个钉钉群,选择自定义机器人 二:添加机器 ...

  3. PHPDocumentor2.8.5 安装,使用及快速上手

    PHPDocumentor当前版本是phpDocumentor-2.8.5.tgz 关于PHPDocumentor有什么用,还有其历史,我就不介绍了,直接进入正题.老版本的叫PHPDoc,从1.0开始 ...

  4. centos7安装jmeter + ant

    1.xshell链接上centos7服务器 先安装jmeter 使用wget  jmeter-xxxxxxxxxxxx进行联网自动下载(先进入jmeter官网,然后找到要下载的.tgz压缩包,然后右键 ...

  5. 了解一下mock

    1.mock简介: mock测试就是在测试过程中,对于某些不容易构成或者不容易获取的对象,用一个虚拟的对象来创建以便测试的测试方法,mock是在测试过程中,对于一些不容易构造/获取的对象,创建一个mo ...

  6. shell执行${var:m:n}报错Bad substitution解决办法

    Ubuntu系统下,执行字符串截取脚本时,总是报错:Bad substitution,脚本非常简单如下: #!/bin/sh str1="hello world!" :} 执行后报 ...

  7. AJ学IOS 之小知识之xcode6自动提示图片插件 KSImageNamed的安装

    AJ分享,必须精品 一:首先看效果 KSImageNamed是让XCode能预览项目中图片的插件 很牛逼,据说写这个插件的牛人在日本~ 主要针对imageNamed:方法 效果如图: 安装: 首先需要 ...

  8. 【LeetCode】23.合并K个排序链表

    题目描述 23.合并K个排序链表 合并k个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6 ] ...

  9. 基于 HTML5 WebGL 的 CPU 监控系统

    前言 科技改变生活,科技的发展带来了生活方式的巨大改变.随着通信技术的不断演进,5G 技术应运而生,随时随地万物互联的时代已经来临.5G 技术不仅带来了更快的连接速度和前所未有的用户体验,也为制造业, ...

  10. 原创hadoop2.6集群环境搭建

    三台机器: Hmaster 172.168.2.3.Hslave1 172.168.2.4.Hslave2 172.168.2.6 JDK:1.8.49 OS:red hat 5.4 64 (由于后期 ...