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秦皇岛分站赛的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python-JS (JS介绍~JS的基
- 下一篇: Friendly Group Gym -