欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

A Greeting from Qinhuangdao Gym - 102769A 2020ccpc秦皇岛分站赛

发布时间:2023/12/4 编程问答 35 豆豆
生活随笔 收集整理的这篇文章主要介绍了 A Greeting from Qinhuangdao Gym - 102769A 2020ccpc秦皇岛分站赛 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

题意:

给你n个红球和m个蓝色球。然后以相等的概率随机选择了其中两个。选择两个红球的概率是多少?

题目:

Welcome to the CCPC Qinhuangdao Site!

Qinhuangdao is a beautiful coastal city full of charm, integrating historical heritage and modern civilization. It was named after the Emperor QinShiHuang’s east tour in 215 BC for seeking immortals.

The infiltration of more than 2000 years of history has left a rich cultural treasure here. Bo Yi, Shu Qi, Qi Jiguang, Cao Cao, and Mao Zedong, Many Heroes throughout the ages have endowed Qinhuangdao with the thousand-year cultural context, the unique and precious heritage, and the profound historical memory.

Pleasant natural scenery has shaped her beautiful appearance. Thousands of miles of Yan Mountains, the Great Wall, and the vast seas are miraculously met here. The blue sky, green land, blue sea, and golden sand gather together to welcome guests.

To toast your arrival, Alex prepared a simple problem to help you warm up.

Alex has red balls and blue balls. Then, Alex randomly chose two of these balls with equal probability. What is the probability that he chose two red balls?

Output the required probability in the form of irreducible fraction.

Input

The first line of input gives the number of test cases, . test cases follow.

For each test case, the only line contains two integers , where is the number of red balls and is the number of blue balls.

Output

For each test case, output one line containing “Case #x: y”, where is the test case number (starting from ), and is the answer in the form of irreducible fraction in format A/B.

If the required probability equals to zero, output 0/1. If the required probability equals to , output 1/1.

Example

Input

3
1 1
2 1
8 8

Output

Case #1: 0/1
Case #2: 1/3
Case #3: 7/30

分析:

1.注意审题,在红球数量小于2时,既不可能存在取两个红球的情况下直接输出0/1;
2.欧几里得算法。

AC代码:

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int t,n,m,k,a,b; int gcd(int a,int b) {return b==0?a:gcd(b,a%b); } int main() {k=1;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);printf("Case #%d: ",k++);if(n<2)printf("0/1\n");else{a=n*(n-1);b=(n+m)*(n+m-1);printf("%d/%d\n",a/gcd(a,b),b/gcd(a,b));}}return 0; }

总结

以上是生活随笔为你收集整理的A Greeting from Qinhuangdao Gym - 102769A 2020ccpc秦皇岛分站赛的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。