HDOJ 2200 Eddy's AC难题(数学组合概率题)

Problem Description
Eddy是个ACMer,他不仅喜欢做ACM题,而且对于Ranklist中每个人的ac数量也有一定的研究,他在无聊时经常在纸上把Ranklist上每个人的ac题目的数量摘录下来,然后从中选择一部分人(或者全部)按照ac的数量分成两组进行比较,他想使第一组中的最小ac数大于第二组中的最大ac数,但是这样的情况会有很多,聪明的你知道这样的情况有多少种吗?

特别说明:为了问题的简化,我们这里假设摘录下的人数为n人,而且每个人ac的数量不会相等,最后结果在64位整数范围内.

Input
输入包含多组数据,每组包含一个整数n,表示从Ranklist上摘录的总人数。

Output
对于每个实例,输出符合要求的总的方案数,每个输出占一行。

Sample Input
2
4

Sample Output
1
17

分析思路:
可以这么想,假设n个人的ac数量按从小到大排列,可以从中任选i个人(n=>i>=2),(C(n,i))种。
再把这i个人分2组(每个人都要分组),要是满足最小ac数大于最大ac数,只需要在i个人中插板即可。例如:
i个人假如分别为 :
1,2,3,4,……i-1,i(i个人的ac数从小到大排列)
只需在任意位置插板就可分为符合要求的2组:
1,2,3……t, || t+1…i-1,i (1<=t< i)
则 1,2,3……t 为一组
t+1,t+2,……i-1,i 为一组
很明显这样分组符合要求,在这i人中共有i-1种分法(t取不同值)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new  Scanner(System.in);
        while(sc.hasNext()){
            double n = sc.nextDouble();
            double sum = 0;
            for(int i=2;i<=n;i++){
                sum = sum+(i-1)*zs(n,i);
            }
            System.out.println((long)(sum+0.5));
        }

    }

    private static double zs(double n, double i) {
        return (jc(n)/jc(i))/jc(n-i);
    }

    private static double jc(double n) {
        double sum = 1;
        for(int i=1;i<=n;i++){
            sum=sum*i;
        }
        return sum;
    }

}
时间: 2024-09-30 11:21:24

HDOJ 2200 Eddy&#39;s AC难题(数学组合概率题)的相关文章

HDOJ 1163 Eddy&amp;#39;s digital Roots(九余数定理的应用)

Problem Description The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits a

HDOJ 1164 Eddy&amp;#39;s research I(拆分成素数因子)

Problem Description Eddy's interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can't write program, so Eddy has to ask intelligent you to h

HDOJ 1210 Eddy&amp;#39;s 洗牌问题

Problem Description Eddy是个ACMer,他不仅喜欢做ACM题,而且对于纸牌也有一定的研究,他在无聊时研究发现,如果他有2N张牌,编号为1,2,3..n,n+1,..2n.这也是最初的牌的顺序.通过一次洗牌可以把牌的序列变为n+1,1,n+2,2,n+3,3,n+4,4..2n,n.那么可以证明,对于任意自然数N,都可以在经过M次洗牌后第一次重新得到初始的顺序.编程对于小于100000的自然数N,求出M的值. Input 每行一个整数N Output 输出与之对应的M Sa

HDOJ/HDU 1161 Eddy&amp;#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ 2037 今年暑假不AC

Problem Description "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@#$%^&*%-" 确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了. 作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事).非常6+7.超级女生,以及王小丫的<

HDOJ 1098 Ignatius&amp;#39;s puzzle

Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find the minimal nonegative integer

HDOJ 1157 Who&amp;#39;s in the Middle

Problem Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give as much or more than the median; half give as much or less. Given an odd number of cows N (1 <= N

HDOJ 1397 Goldbach&amp;#39;s Conjecture(快速筛选素数法)

Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2. This conjecture has not been proved nor refused yet. No one is sure whether

UVa 10177 (2/3/4)-D Sqr/Rects/Cubes/Boxes? (数学好题)

10177 - (2/3/4)-D Sqr/Rects/Cubes/Boxes? Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1118 You can see a (4x4) grid below. Can you tell me how many squ