Dogs and Cages_数学+2018_3_18

Jerry likes dogs. He has N dogs numbered 0,1,...,N1. He also has N cages numbered 0,1,...,N1
. Everyday he takes all his dogs out and walks them outside. When he is back home, as dogs can’t recognize the numbers, each dog just randomly selects a cage and enters it. Each cage can hold only one dog.
One day, Jerry noticed that some dogs were in the cage with the same number of themselves while others were not. Jerry would like to know what’s the expected number of dogs that are NOT in the cage with the same number of themselves.
Input The first line of the input gives the number of test cases, T. T test cases follow.
Each test case contains only one number N, indicating the number of dogs and cages.
1T105
1N105
Output For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the expected number of dogs that are NOT in the cage with the same number of itself.
y will be considered correct if it is within an absolute or relative error of 106 of the correct answer. Sample Input
2
1
2
Sample Output
Case #1: 0.0000000000
Case #2: 1.0000000000

        
  
Hint
In the first test case, the only dog will enter the only cage. So the answer is 0.
In the second test case, if the first dog enters the cage of the same number, both dogs are in the cage of the same number, 
the number of mismatch is 0. If both dogs are not in the cage with the same number of itself, the number of mismatch is 2. 
So the expected number is (0+2)/2=1. 
 
 
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int a;
		scanf("%d",&a);
		printf("Case #%d: %d.0000000000\n",i,a-1);
	}
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值