CSUOJ 1638 Continued Fraction
2015-06-04 23:06
585 查看
1638: Continued Fraction
Time Limit: 1 Sec Memory Limit: 128 MBDescription
#include <bits/stdc++.h> using namespace std; typedef long long LL; int n,m,a1[20],a2[20]; LL gcd(LL x,LL y){ return y?gcd(y,x%y):x; } void dfs(LL &A,LL &B,int *arr,int cur,int dep){ if(cur == dep-1){ A = arr[cur]; B = 1; } if(cur >= dep-1) return; LL tmpA,tmpB; dfs(tmpA,tmpB,arr,cur+1,dep); LL theGCD = gcd(A = arr[cur]*tmpA + tmpB,B = tmpA); A /= theGCD; B /= theGCD; } void print(LL x,LL y){ LL GCD = gcd(x,y); LL tmp = (x /= GCD)/(y /= GCD),p = x - tmp*y; printf("%lld%c",tmp,p?' ':'\n'); if(p) print(y,p); } int main(){ while(~scanf("%d %d",&n,&m)){ for(int i = 0; i < n; ++i) scanf("%d",a1+i); for(int i = 0; i < m; ++i) scanf("%d",a2+i); LL A1 = 0,B1 = 1,A2 = 0,B2 = 1; dfs(B1,A1,a1,1,n); dfs(B2,A2,a2,1,m); A1 += a1[0]*B1; A2 += a2[0]*B2; print(A1*B2 + A2*B1,B1*B2); print(A1*B2 - A2*B1,B1*B2); print(A1*A2,B1*B2); print(A1*B2,A2*B1); } return 0; }
View Code
相关文章推荐
- [Algorithms] Sorting Algorithms (Insertion Sort, Bubble Sort, Merge Sort and Quicksort)
- iOS-学习笔记-UI-第三天
- UITableView的性能优化
- Android 如何在自定义界面上启用输入法 (How to enable inputmethod for the custom UI)
- SPOJ QTREE Query on a tree
- NSValue
- 人机交互设计——“搜狗输入法”分析
- UIImageView 基本用法
- easyui提交表单数据的时候如何防止二次提交
- Ueditor结合七牛云及百度云存储(JAVA版,ueditor-1.4.3)实现图片文件上传
- STL之deque
- UIScrollView
- UITableView固定表头
- STL --> queue单向队列
- [UI] 精美UI界面欣赏[10]
- STL --> deque双向队列
- UIScrollView使用注意
- 向量空间模型实现文档查询(Vector Space Model to realize document query)
- 【easyui】--普通js中获取easyui中分页信息(page,pageSize等)
- 【easyui】--combobox--赋值和获取选中的值