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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/309519.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Gartner:6个容器和Kubernetes策略的最佳实用技巧

导语采用容器和Kubernetes要求整个企业保持一致&#xff0c;不了解这些前期现实会导致一些非常严峻的后果。正文Gartner估计&#xff0c;到2022年&#xff0c;将有75&#xff05;的组织在生产中运行容器化应用程序。毫无疑问&#xff0c;Kubernetes已成为组织容器的流行方法。通…

[JavaWeb-MySQL]约束(非空约束,唯一约束,主键约束,外键约束_级联操作)

约束 * 概念&#xff1a; 对表中的数据进行限定&#xff0c;保证数据的正确性、有效性和完整性。 * 分类&#xff1a;1. 主键约束&#xff1a;primary key2. 非空约束&#xff1a;not null3. 唯一约束&#xff1a;unique4. 外键约束&#xff1a;foreign key* 非空约束&#x…

Friendly Group Gym - 102769F 2020(并查集)ccpc秦皇岛分站赛

题意&#xff1a; n个学生要组成一个小组参加会议&#xff08;可以不参加&#xff09;&#xff0c; 1.对于每两个朋友&#xff08;x &#xff0c;y)&#xff0c;如果他们俩都参加会议&#xff0c;该小组的友好价值将会增加 1&#xff1b;如果其中只有一位参加会议&#xff0c;…

测试人员未来的3条出路

大家好&#xff0c;我是Z哥。前两天有个做测试的小伙伴加我微信问我测试相关的一些事情。她自己是从学习毕业就开始进入到互联网行业做测试的&#xff0c;到现在三年工作经验。她现在都不太敢跳槽&#xff0c;因为觉得自己没有什么核心竞争力&#xff0c;平常就是点点鼠标&…

[JavaWeb-MySQL]DQL_查询表中记录,语句

DQL&#xff1a;查询表中的记录 * select * from 表名;1. 语法&#xff1a;select字段列表from表名列表where条件列表group by分组字段having分组之后的条件order by排序limit分页限定2. 基础查询1. 多个字段的查询select 字段名1&#xff0c;字段名2... from 表名&#xff1b…

团体程序设计天梯赛-练习集L1-025 正整数A+B (15分)(getline输入)

题目&#xff1a; 题的目标很简单&#xff0c;就是求两个正整数A和B的和&#xff0c;其中A和B都在区间[1,1000]。稍微有点麻烦的是&#xff0c;输入并不保证是两个正整数。 输入格式&#xff1a; 输入在一行给出A和B&#xff0c;其间以空格分开。问题是A和B不一定是满足要求…

自定义值类型一定不要忘了重写Equals,否则性能和空间双双堪忧

一&#xff1a;背景1. 讲故事曾今在项目中发现有同事自定义结构体的时候&#xff0c;居然没有重写Equals方法&#xff0c;比如下面这段代码&#xff1a;static void Main(string[] args){var list Enumerable.Range(0, 1000).Select(m > new Point(m, m)).ToList();var ite…

[JavaWeb-MySQL]DDL_操作数据库,表

DDL:操作数据库、表 1. 操作数据库&#xff1a;CRUD1. C(Create):创建* 创建数据库&#xff1a;* create database 数据库名称;* 创建数据库&#xff0c;判断不存在&#xff0c;再创建&#xff1a;* create database if not exists 数据库名称;* 创建数据库&#xff0c;并指定…

Division CodeForces - 1445C(数论因子相关)

题意&#xff1a; 找一个最大的数X&#xff0c;使p%x0且x%q!0&#xff0c;题目保证至少有一个答案满足题意。 题目&#xff1a; Oleg’s favorite subjects are History and Math, and his favorite branch of mathematics is division. To improve his division skills, O…

使用 Windows Terminal 连接远程主机

使用 Windows Terminal 连接远程主机IntroWindows Terminal 是微软新推出来的一个全新的、流行的、功能强大的命令行终端工具。包含很多来社区呼声很高的特性&#xff0c;例如&#xff1a;多 Tab 支持、富文本、多语言支持、可配置、主题和样式&#xff0c;支持 emoji 和基于 G…

[JavaWeb-MySQL]DML_操作表

DML&#xff1a;增删改表中数据 1. 添加数据&#xff1a;* 语法&#xff1a;* insert into 表名(列名1,列名2,...列名n) values(值1,值2,...值n);* 注意&#xff1a;1. 列名和值要一一对应。2. 如果表名后&#xff0c;不定义列名&#xff0c;则默认给所有列添加值insert into …

.Net Core实现区块链初探

区块链这么火&#xff0c;咱也跟个风。一、前言最近&#xff0c;银行总行关于数字货币即将推出的消息频传&#xff0c;把BTC也带得来了一波反弹。借着这个风&#xff0c;我们也研究一下区块链。通常大家说到区块链&#xff0c;实际包括两部分概念&#xff1a;第一个概念&#x…

Divide and Sum CodeForces - 1445D(排列组合+逆元)

题意&#xff1a; 给定一个长度为2n的数组&#xff0c;将数组分成两个长度为n的数组p,q&#xff0c;将p从小到大排序&#xff0c;将q从大到小排序&#xff0c;对于每种分法&#xff0c;f(p,q)∑i1n\sum_{i1}^{n}∑i1n​|xi−yi|.求总和 题目&#xff1a; You are given an a…

[Java基础]自定义注解之属性定义

代码如下: package AnnoDemo01;public enum Person {p1,p2; }package AnnoDemo01;public interface MyAnno2 {}package AnnoDemo01;public interface MyAnno {int show1();String show2();Person per();MyAnno2 ann02();String[] strs(); }定义了属性&#xff0c;在使用时需要…

微软开源 Tye 项目,可简化微服务开发

微软近期开源了一款开发人员工具 Tye&#xff0c;能够用于简化微服务以及分布式应用程序的开发、测试以及部署过程。项目地址&#xff1a;https://github.com/dotnet/tye。该项目负责人 Amiee 表示&#xff0c;在构建由多个项目组成的应用程序时&#xff0c;开发者通常希望能够…

Subset POJ - 3977(折半枚举+二分+二进制枚举)

题意&#xff1a; 给你一个集合N&#xff08;N<35&#xff09;,问集合的子集&#xff0c;除了空集&#xff0c;使得自己中所有元素和的绝对值最小&#xff0c;若存在多个值&#xff0c;那么选择子集中元素最少的那个。 题目&#xff1a; Given a list of N integers with…

.NET内存管理五大基础知识

1.小对象怎么处理的&#xff1f;小型.NET对象被分配到小型对象堆&#xff08;SOH&#xff09;上。其中有3种&#xff1a;第0代&#xff0c;第1代和第2代。对象根据其寿命向上移动。将新对象放在Gen 0上。当Gen 0充满时&#xff0c;.NET垃圾收集器&#xff08;GC&#xff09;运行…

L1-046 整除光棍 (20分)(模拟除法竖式求商的位运算)

题目&#xff1a; 这里所谓的“光棍”&#xff0c;并不是指单身汪啦~ 说的是全部由1组成的数字&#xff0c;比如1、11、111、1111等。传说任何一个光棍都能被一个不以5结尾的奇数整除。比如&#xff0c;111111就可以被13整除。 现在&#xff0c;你的程序要读入一个整数x&#…

Sql Server之旅——第十站 简单说说sqlserver的执行计划

我们知道sql在底层的执行给我们上层人员开了一个窗口&#xff0c;那就是执行计划&#xff0c;有了执行计划之后&#xff0c;我们就清楚了那些烂sql是怎么执行的&#xff0c;这样 就可以方便的找到sql的缺陷和优化点。一&#xff1a;执行计划生成过程说到执行计划&#xff0c;首…