hdoj-1570A C

来源:互联网 发布:怎么知道淘宝店铺降权 编辑:程序博客网 时间:2024/05/29 18:53

A C

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5689    Accepted Submission(s): 3700


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
2A 10 10C 4 2
 

Sample Output
36288006
 
题目链接

公式都给了,那就套公式吧。
#include<iostream>#include<cstdio>using namespace std;int jc(int n){    int sum=1;    for(int i=1;i<=n;i++)        sum*=i;    return sum;}int A(int m,int n){    return jc(n)/jc(n-m);}int C(int m,int n){    return A(m,n)/jc(m);}int main(){    char c;    int t,m,n;    scanf("%d",&t);    while(t--)    {        getchar();        scanf("%c%d%d",&c,&n,&m);        if(c=='A')            printf("%d\n",A(m,n));        else            printf("%d\n",C(m,n));    }    return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 孩子13不懂礼貌怎么办 老师不重视你 怎么办 我娃好动不听话怎么办 初三娃不听话该怎么办 小孩爱动不听话怎么办 宝宝吃饭讨神怎么办 孩子速度太慢怎么办 一年级做作业慢怎么办 小学三年级数学差怎么办 拼音基础太差怎么办 小孩学拼音差怎么办? 孩子字词基础差怎么办 孩子的语文不好怎么办 数学一直学不好怎么办 小孩数学成绩差怎么办 理科生语文不好怎么办 小学阅读题不好怎么办 如果孩子考不好怎么办 6岁不认识数字怎么办 数学一点都不会怎么办 初一数学太差怎么办 三年级孩子数学差怎么办 三年级孩子数学很差怎么办 初中学习不好高中怎么办 四年级孩子数学不好怎么办 孩子学习不开窍怎么办 孩子学习太笨怎么办 老师是个小人怎么办 孩子写字太差怎么办 孩子写字下手重怎么办 孩子一年级数学不好怎么办 孩子数学理解能力差怎么办 智商情商都低怎么办 一年级孩子数学很差怎么办 一年级孩子数学差怎么办 一年级数学学不好怎么办 孩子成绩差该怎么办 小学生数学太差怎么办 小学数学基础差怎么办 孩子一年级学习不好怎么办 快两岁的宝宝老尿裤怎么办