hdu 5912(迭代+gcd)
Fraction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 97 Accepted Submission(s): 64
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?
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).
You should promise that p/q is irreducible.
2
1 1
2 3
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)的更多相关文章
- HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))
Fraction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 5912 Fraction(模拟——分子式化简求解)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5912 Problem Description Mr. Frog recently studied h ...
- HDU 5869 Different GCD Subarray Query (GCD种类预处理+树状数组维护)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5869 问你l~r之间的连续序列的gcd种类. 首先固定右端点,预处理gcd不同尽量靠右的位置(此时gc ...
- HDU 5869 Different GCD Subarray Query
离线操作,树状数组,$RMQ$. 这个题的本质和$HDU$ $3333$是一样的,$HDU$ $3333$要求计算区间内不同的数字有几个. 这题稍微变了一下,相当于原来扫描到$i$的之后是更新$a[i ...
- HDU 5512 - Pagodas - [gcd解决博弈]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5512 Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 5869 Different GCD Subarray Query rmq+离线+数状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5869 Different GCD Subarray Query Time Limit: 6000/3 ...
- HDU 5869 Different GCD Subarray Query 树状数组 + 一些数学背景
http://acm.hdu.edu.cn/showproblem.php?pid=5869 题意:给定一个数组,然后给出若干个询问,询问[L, R]中,有多少个子数组的gcd是不同的. 就是[L, ...
- hdu 6053 trick gcd 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给定一个数组,我们定义一个新的数组b满足bi<ai 求满足gcd(b1,b2....bn)&g ...
- HDU 5869 Different GCD Subarray Query 离线+树状数组
Different GCD Subarray Query Problem Description This is a simple problem. The teacher gives Bob a ...
随机推荐
- C++之面向对象编程20170912
/*************************************************************************************************** ...
- PID控制算法的C语言实现八 变积分的PID控制算法C语言实现
变积分PID可以看成是积分分离的PID算法的更一般的形式.在普通的PID控制算法中,由于积分系数ki是常数,所以在整个控制过程中,积分增量是不变的.但是,系统对于积分项的要求是,系统偏差大时,积分作用 ...
- 多线程中join方法的含义
1.作用:调用这个方法的时候,主进程会在这里停住,等待该线程进行完毕再继续往下执行. 如:不使用join的情况: <?php class Join extends Thread { public ...
- [ldap]ldap server安装以及图形化操作
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-a-basic-ldap-server-on ...
- 手脱PEncrypt 4.0
1.载入PEID PEncrypt 4.0 Gamma / 4.0 Phi -> junkcode [Overlay] 2.载入OD,没什么头绪,忽略所有异常,用最后一次异常法shift+F9运 ...
- 「Django」rest_framework学习系列-用户认证
用户认证:1.项目下utils文件写auth.py文件 from rest_framework import exceptions from api import models from rest_f ...
- 「Linux」centos7安装使用rar
安装 1 wget https://www.rarlab.com/rar/rarlinux-x64-5.5.0.tar.gz 2 tar -xzvf rarlinux-x64-5.5.0.tar.gz ...
- 前端PHP入门-032-异常处理-应用级别
禁止显示错误 在php.ini配置文件中.我们可以控制php的错误显示状态. php.ini中有一个专门的配置项: display_errors 这个选项设置是否将错误信息输出到网页,或者对用户隐藏而 ...
- MyEclipse+Weblogic+Oracle+PLSQL配置注意事项
Weblogic配置详情:<Weblogic安装与配置图文详解>Oracle+PLSQL配置详情:<PL/SQL访问远程Oracle服务器(多种方式)>MyEclipse配置: ...
- oracle的小语句
select * from v$nls_parameters; 查询数据库中现在的常量 alter session set NLS_DATE_FORMAT='yyyy-mm-dd'; 更改日期显示方式