当前位置:网站首页>A - Eddy's AC puzzle (C language)

A - Eddy's AC puzzle (C language)

2022-06-11 03:57:00 Luo 907

One 、 subject

Eddy It's a ACMer, He not only likes to do ACM topic , And for Ranklist Everyone in the ac There is also a certain amount of research , When he is bored, he often puts... On paper Ranklist Everyone in the world ac The number of topics is extracted , Then select some of them ( Or all ) according to ac The quantity of is divided into two groups for comparison , He wants to be the smallest in the first group ac The number is greater than the maximum in the second group ac Count , But there will be many such cases , Smart, do you know how many such situations there are ?
In particular : In order to simplify the problem , Here we assume that the number of people excerpted is n people , And everyone ac The number of will not be equal , The final result is 64 Bit integer range .

Input format :

The input contains multiple sets of data , Each group contains an integer n, From Ranklist The total number of people excerpted from .

Output format :

For each instance , Output the total number of schemes that meet the requirements , One line per output .

Sample
Inputcopy Outputcopy

2
4

	

1
17

Two 、 Solution

1. Ideas

① Thinking of this topic , First, in the n In the personal , We are free to choose (2~n) personal , Write it down as i, According to the arrangement  Insert picture description here
We can get the result of how many permutations and combinations there are , And in each set of results , Because the numbers don't repeat , We can know that there is (i-1) There are different grouping methods .
② The title requires that the results be 64 Bit integer range , So we define that data can be used long long Type or double type , What I'm using here is double.

——————————————

2. Code

#include<stdio.h>
double func(double t)
{
    
	if(t==0)
	{
    
		return 1;
	}
	double x=1;
	for(double i=2;i<=t;i++)
	{
    
		x *= i;
	}
	return x;
}
double C(double x,long long y)
{
    
	return func(y)*1.0/func(x)/func(y-x);
}
int main()
{
    
	double n=0;
	while(scanf("%lf",&n) != EOF)
	{
    
		double sum = 0;
		for(double i=2;i<=n;i++)
		{
    
			sum += (i-1)*C(i,n);
		}
		printf("%.0f\n",sum);
	}
	return 0;
}
原网站

版权声明
本文为[Luo 907]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110337365700.html