HDU 6243 Dogs and Cages

Problem Description: Jerry likes dogs. He hasNdogs numbered0,1,...,N1. He also hasNcages numbered0,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;
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324727090&siteId=291194637