HDOJ(HDU) 1570 A C

Problem Description

Are you excited when you see the title “AC” ? If the answer is YES , AC it ;

You must learn these two combination formulas in the school . If you have forgotten it , see the picture.

Now I will give you n and m , and your task is to calculate the answer .

Input

In the first line , there is a integer T indicates the number of test cases.

Then T cases follows in the T lines.

Each case contains a character ‘A’ or ‘C’, two integers represent n and m. (1<=n,m<=10)

Output

For each case , if the character is ‘A’ , calculate A(m,n),and if the character is ‘C’ , calculate C(m,n).

And print the answer in a single line.

Sample Input

2

A 10 10

C 4 2

Sample Output

3628800

6

题意:很简单,看图片就能理解了。

水题一个!就不多解释了。

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            String str = sc.next();
            int n = sc.nextInt();
            int m =sc.nextInt();

            if(str.charAt(0)==‘A‘){
                System.out.println(a(n,m));
            }else{
                System.out.println(c(n,m));
            }

        }

    }

    private static int c(int n, int m) {
        int num =1;
        if(n-m>m){
            m=n-m;
        }
        int cnum=1;
        for(int i=1;i<=n-m;i++){
            cnum=cnum*i;
        }
        for(int i=m+1;i<=n;i++){
            num=num*i;
        }
        return num/cnum;
    }

    private static int a(int n, int m) {
        int num=1;
        for(int i=n-m+1;i<=n;i++){
            num=num*i;
        }
        return num;
    }
}
时间: 2024-08-13 09:56:57

HDOJ(HDU) 1570 A C的相关文章

HDOJ/HDU 2140 Michael Scofield&#39;s letter(字符转换~)

Problem Description I believe many people are the fans of prison break. How clever Michael is!! In order that the message won't be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the he

HDOJ/HDU 1161 Eddy&#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/HDU 1250 Hat&#39;s Fibonacci(大数~斐波拉契)

Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) Your task is to take

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can be played by two or more t

HDOJ(HDU) 2500 做一个正气的杭电人(水~)

Problem Description 做人要有一身正气,杭电学子都应该如此.比如我们今天的考试就应该做到"诚信"为上. 每次考试的第一个题目总是很简单,今天也不例外,本题是要求输出指定大小的"HDU"字符串,特别地,为了体现"正气"二字,我们要求输出的字符串也是正方形的(行数和列数相等). Input 输入的第一行包含一个正整数N(N<=20),表示一共有N组数据,接着是N行数据,每行包含一个正整数M(M<=50),表示一行内有M个

hdoj HDU Today

HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16803    Accepted Submission(s): 3968 Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候

HDOJ/HDU 1062 Text Reverse(字符串翻转~)

Problem Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first line of the inpu

杭电 HDU 1570 A C

A C Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4206    Accepted Submission(s): 2671 Problem Description Are you excited when you see the title "AC" ? If the answer is YES , AC it ; Yo

HDOJ HDU Today 2112【最短路】

HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 19366    Accepted Submission(s): 4552 Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候