【HDU - 5912】Fraction (模拟)

题干:

Mr. Frog recently studied how to add two fractions up, and he came up with an evil idea to trouble you by asking you to calculate the result of the formula below: 
 

As a talent, can you figure out the answer correctly?

Input

The first line contains only one integer T, which indicates the number of test cases. 

For each test case, the first line contains only one integer n (n≤8n≤8). 

The second line contains n integers: a1,a2,⋯an(1≤ai≤10a1,a2,⋯an(1≤ai≤10). 
The third line contains n integers: b1,b2,⋯,bn(1≤bi≤10)b1,b2,⋯,bn(1≤bi≤10).

Output

For each case, print a line “Case #x: p q”, where x is the case number (starting from 1) and p/q indicates the answer. 

You should promise that p/q is irreducible.

Sample Input

1
2
1 1
2 3

Sample Output

Case #1: 1 2

Hint

Here are the details for the first sample:
2/(1+3/1) = 1/2

题目大意:

   给你两个长度为n的数组a,b,请你计算出下图中表达式的结果的最简分数形式。 

解题报告:

      直接模拟分子和分母即可,带入一个样例来查看循环的次数,就的出来了需要循环n-2次。最后要求最简分式所以需要除以他俩的gcd就可以了。

AC代码:

#include<bits/stdc++.h>using namespace std;
int a[10],b[10];
int gcd(int a,int b) {while(a^=b^=a^=b%=a);return b;
}
int main()
{int t,iCase = 0;int n;cin>>t;while(t--) {scanf("%d",&n); for(int i = 1; i<=n; i++) {scanf("%d",&a[i]);}for(int i = 1; i<=n; i++) {scanf("%d",&b[i]);}int zi = b[n],mu=a[n],tmp;while(n >= 2) {zi +=a[n-1] * mu;tmp = mu;mu = zi;zi = tmp * b[n-1];n--;}int g = gcd(zi,mu);printf("Case #%d:",++iCase);printf(" %d %d\n",zi/g,mu/g);}	return 0 ;
}

 

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

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

相关文章

vue mysql webapp_基于Laravel+VueJS实战开发WebAPP

资源介绍【课程内容】1-git库与开发环境及工具软件介绍2-安装laravel框架3-安装laravel-ide-helper增强代码提示4-配置数据库与使用migrations创建表5-解决mysql5.7以下laravel不能执行数据迁移的问题6-合理的路由布局与分组路由7-远程开发环境服务器搭建与虚拟面板的使用8-使用…

计算机测试怎么提交,Win7电脑怎么测试上传速度?

做网站的人都知道上传速度是很重要的&#xff0c;因为太差的上传速度会影响工作的进度&#xff0c;所以他们经常要对上传速度进行测试&#xff0c;但是有一些新手不知道Win7电脑怎么测试上传速度&#xff1f;为此小编赶紧整理了以下教程&#xff0c;不知道的朋友赶紧来看看吧&a…

【HDU - 5914 】Triangle (打表 或 set维护)

题干&#xff1a; Mr. Frog has n sticks, whose lengths are 1,2, 3⋯⋯n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks! Output the minimal number of sticks h…

harmonyos消息服务器,第三方纯HarmonyOS应用太少,你还愿意升级吗?

部分纯鸿蒙 HarmonyOS 应用已上线&#xff1a;图标多了“HMOS”角标标识&#xff0c;而只有真正的鸿蒙系统应用才能真正体验到万能卡片等系列的功能&#xff0c;但是很明显目前真正属于鸿蒙系统的第三方应用太少……基本上都是华为自身的应用&#xff0c;那么如果应用太少你还愿…

如何释放mysql连接资源_CI框架出现mysql数据库连接资源无法释放的解决方法

本文实例分析了CI框架出现mysql数据库连接资源无法释放的解决方法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;使用ci框架提供的类查询数据&#xff1a; $this->load->database();$query $this->db->query($sql);程序运行一段时间之后&#xff0c;报错…

【nyoj - 860】 又见0-1背包 (dp,反向0-1背包,好题好思路)

题干&#xff1a; 又见01背包 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB 难度&#xff1a;3 输入 多组测试数据。 每组测试数据第一行输入&#xff0c;n 和 W &#xff0c;接下来有n行&#xff0c;每行输入两个数&#xff0c;代表第i个物品的wi 和 v…

300英雄服务器维护多久,《300英雄》2021年5月20日6:00-9:00更新维护公告

尊敬的《300英雄》玩家:《300英雄》将于2021年5月20日6:00-9:00(星期四)&#xff0c;对所有大区进行停机更新&#xff0c;更新期间&#xff0c;您将无法登录游戏。如果在预定时间内无法完成维护内容&#xff0c;开服时间也将继续顺延。具体更新内容如下&#xff1a;一、活动相关…

c 连接mysql示例 源码_MySQL 连接

MySQL 连接使用mysql二进制方式连接您可以使用MySQL二进制方式进入到mysql命令提示符下来连接MySQL数据库。实例以下是从命令行中连接mysql服务器的简单实例&#xff1a;[[email protected]]# mysql -u root -pEnter password:******在登录成功后会出现 mysql> 命令提示窗口…

【 FZU - 2214 】Knapsack problem(逆向0-1背包)

题干&#xff1a; Given a set of n items, each with a weight w[i] and a value v[i], determine a way to choose the items into a knapsack so that the total weight is less than or equal to a given limit B and the total value is as large as possible. Find the …

服务器2008系统如何设置休眠时间,Win7休眠和睡眠怎么开启(Win2008)

如果把 Win7休眠和睡眠关闭了&#xff0c;需要的时候可以用命令重新开启&#xff0c;毕竟这两个功能不但可以节约电&#xff0c;还可以迅速恢复工作状态&#xff0c;节约开机开软件的时间。Win2008 R2 跟 Win7 同一内核&#xff0c;开启休眠和睡眠的命令也一样。在开启休眠和睡…

【HDU - 1220】Cube (组合数学,简单)

题干&#xff1a; Cowl is good at solving math problems. One day a friend asked him such a question: You are given a cube whose edge length is N, it is cut by the planes that was paralleled to its side planes into N * N * N unit cubes. Two unit cubes may h…

java poi读取word中附件_Java POI导入word, 带图片

1.导入文件示例&#xff0c;word中简历表格模板2.代码示例分两部分&#xff0c;一部分读取图片/*** 导入word(基本信息&#xff0c;word格式)* param staffId* param baseInfoFile*/void importStaffInfo(Integer staffId, MultipartFile file);-- 读取图片InputStream inputSt…

如何将文件拷贝服务器上,如何将文件复制到云服务器上

如何将文件复制到云服务器上 内容精选换一换将文件上传至Windows云服务器一般会采用MSTSC远程桌面连接的方式。本节为您介绍本地Windows计算机通过远程桌面连接&#xff0c;上传文件至Windows云服务器的操作方法。Windows云服务器可以访问公网。在本地Windows计算机上&#xff…

mysql5.7解压版错误_mysql 5.7 解压版 安装net start mysql 发生系统错误 2

1.配置环境变量 用户变量path 添加 mysql 安装目录2.新建my.ini文件 放到E:\mysql-5.7.24-winx64安装目录下[mysqld]port 3306basedirC:/software/mysql-5.7.21-winx64datadirC:/software/mysql-5.7.21-winx64/datamax_connections200character-set-serverutf8default-storage…

【HDU - 2553】N皇后问题 (dfs经典问题,回溯,搜索)

题干&#xff1a; 在N*N的方格棋盘放置了N个皇后&#xff0c;使得它们不相互攻击&#xff08;即任意2个皇后不允许处在同一排&#xff0c;同一列&#xff0c;也不允许处在与棋盘边框成45角的斜线上。 你的任务是&#xff0c;对于给定的N&#xff0c;求出有多少种合法的放置方…

浪潮服务器建立虚拟驱动器,像《十二时辰》一样去建立标准! 浪潮这款服务器做到了...

原标题&#xff1a;像《十二时辰》一样去建立标准&#xff01; 浪潮这款服务器做到了这个夏天&#xff0c;《长安十二时辰》制霸屏幕开画至今豆瓣评分达到8.8分现已成功“出海”在Amazon、Youtube、Viki付费上线成为唐风古韵的又一风向标现如今&#xff0c;越洋的标准可不止悠悠…

【HDU - 5918 】Sequence I (数组(字符串)匹配问题,可选KMP)

题干&#xff1a; Mr. Frog has two sequences a1,a2,⋯,ana1,a2,⋯,an and b1,b2,⋯,bmb1,b2,⋯,bm and a number p. He wants to know the number of positions q such that sequence b1,b2,⋯,bmb1,b2,⋯,bm is exactly the sequence aq,aqp,aq2p,⋯,aq(m−1)paq,aqp,aq2p,…

mysql_fetch_bit_mysql_fetch_array()

mysql_fetch_array()(PHP 4, PHP 5)从结果集中取得一行作为关联数组&#xff0c;或数字数组&#xff0c;或二者兼有说明mysql_fetch_array(resource$result[,int$ result_type]):array返回根据从结果集取得的行生成的数组&#xff0c;如果没有更多行则返回FALSE。mysql_fetch_a…

【HDU - 5916】Harmonic Value Description (构造,思维,SJ题)

题干&#xff1a; The harmonic value of the permutation p1,p2,⋯pnp1,p2,⋯pn is ∑i1n−1gcd(pi.pi1)∑i1n−1gcd(pi.pi1) Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n]. Inpu…

在python中、对于函数定义代码的理解_python中如何理解装饰器代码?

长文预警&#xff0c;【最浅显易懂的装饰器讲解】能不能专业地复制题目&#xff1f;配上代码&#xff0c;问题分段。我来给提主配上问题的代码。正式回答&#xff1a;1&#xff1a;如何理解return一个函数&#xff0c;它与return一个值得用法区别在哪&#xff1f;敲黑板&#x…