Fraction

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 97    Accepted Submission(s): 64

Problem Description
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≤8).

The second line contains n integers: a1,a2,⋯an(1≤ai≤10).
The third line contains n integers: 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

 
题意:求图上的公式的结果.直接迭代求然后约分
#include <bits/stdc++.h>
using namespace std;
map<int ,int> value;
int a[],b[];
int gcd(int x,int y){
return y==?x:gcd(y,x%y);
}
int main()
{
int tcase,t=;
scanf("%d",&tcase);
while(tcase--){
int n,res1,res2;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
res1 = a[n],res2 = b[n];
for(int i=n-;i>=;i--){
int k = res1;
res1 = a[i]*res1+res2;
res2 = b[i]*k;
}
int d = gcd(res1,res2);
printf("Case #%d: %d %d\n",t++,res2/d,res1/d);
}
return ;
}

hdu 5912(迭代+gcd)的更多相关文章

  1. HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Fraction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  2. HDU 5912 Fraction(模拟——分子式化简求解)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5912 Problem Description Mr. Frog recently studied h ...

  3. HDU 5869 Different GCD Subarray Query (GCD种类预处理+树状数组维护)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5869 问你l~r之间的连续序列的gcd种类. 首先固定右端点,预处理gcd不同尽量靠右的位置(此时gc ...

  4. HDU 5869 Different GCD Subarray Query

    离线操作,树状数组,$RMQ$. 这个题的本质和$HDU$ $3333$是一样的,$HDU$ $3333$要求计算区间内不同的数字有几个. 这题稍微变了一下,相当于原来扫描到$i$的之后是更新$a[i ...

  5. HDU 5512 - Pagodas - [gcd解决博弈]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5512 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  6. HDU 5869 Different GCD Subarray Query rmq+离线+数状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5869 Different GCD Subarray Query Time Limit: 6000/3 ...

  7. HDU 5869 Different GCD Subarray Query 树状数组 + 一些数学背景

    http://acm.hdu.edu.cn/showproblem.php?pid=5869 题意:给定一个数组,然后给出若干个询问,询问[L, R]中,有多少个子数组的gcd是不同的. 就是[L, ...

  8. hdu 6053 trick gcd 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给定一个数组,我们定义一个新的数组b满足bi<ai 求满足gcd(b1,b2....bn)&g ...

  9. HDU 5869 Different GCD Subarray Query 离线+树状数组

    Different GCD Subarray Query Problem Description   This is a simple problem. The teacher gives Bob a ...

随机推荐

  1. 服务器启动脚本 /etc/rc.local

    #启动php-frm/home/www/php/sbin/php-fpm #启动搜索引擎/home/www/se/bin/xs-ctl.sh start #启动lighttpd/home/www/li ...

  2. 前端基础----JavaScript基础

    一.JavaScript概述 1,JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEa ...

  3. java如何优雅的实现时间控制

    前言:最近小王同学又遇到了一个需求:线上的业务运行了一段时间,后来随着使用人数增多,出现了一个问题是这样的,一个订单会重复创建几次,导致数据库里出现了很多垃圾数据.在测试同学的不断测试下,发现问题出在 ...

  4. 批量修改历史commit的用户名user.name邮箱user.email

    配置当前的用户名邮箱可以当前项目配置或者全局配置. 仅当前项目配置: git config user.name 'your-user-name' git config user.email 'your ...

  5. vue2.0 安装及项目搭建(一)

    基本环境安装 1.安装node:从node.js官网下载并安装node.测试:win+R(打开命令行)-------输入cmd-------敲入node -v.如果出现相应版本号,即安装成功: 2.测 ...

  6. selenium - Select类 - 下拉框

    WebDriver提供了Select类来处理下拉框. 如百度搜索设置的下拉框,如下图: from selenium import webdriver from selenium.webdriver.s ...

  7. Linux系统之路——python多版本共存问题(ps:自行切换python版本,pip安装遇到的一些问题)

    经常遇到这样的情况: 系统自带的Python是2.6,自己需要Python 2.7中的某些特性: 系统自带的Python是2.x,自己需要Python 3.x: 此时需要在系统中安装多个Python, ...

  8. springboot如何集成mybatis的pagehelper分页插件

    mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...

  9. python--生成器协程运算

    生成器 一.yield运行方式 我们定义一个如下的生成器: def put_on(name): print("Hi {}, 货物来了,准备搬到仓库!".format(name)) ...

  10. java rmi远程方法调用实例

    RMI的概念 RMI(Remote Method Invocation)远程方法调用是一种计算机之间利用远程对象互相调用实现双方通讯的一种通讯机制.使用这种机制,某一台计算机上的对象可以调用另外一台计 ...