HDU 6243 Dogs and Cages

Problem Description: 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.

Analysis: [N*A(N,N)-N*A(N-1,N-1)]/A(N,N)=N-1,so,we just need to putout N-1,and a set '0'.

#include<stdio.h>
int main(){
	int T,ca=1;
	scanf("%d",&T);
	while(T--){
		int N;
		scanf("%d",&N);
		printf("Case #%d: %d.0000000000\n",ca++,N-1);
	}
	return 0;
}



猜你喜欢

转载自blog.csdn.net/Triple_WDF/article/details/80056509
今日推荐