HDU 5912 Fraction (2016-ccpc-长春)
来源:互联网 发布:数据流程图例题 编辑:程序博客网 时间:2024/05/16 10:37
题目连接:题目
求公式结果,数据量比较小,递归一下就行了,和某年的蓝桥杯一个题一样
#include<cmath>#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn = 10;int n;int a[maxn],b[maxn];int gcd(int x,int y){ if(x==0) return y; else return gcd(y%x,x);}void dfs(int &x,int &y,int t){ if(t==n){ x=a[t-1]*a[t]+b[t]; y=a[t]; }else{ dfs(x,y,t+1); int q,p;q=a[t-1]*x+b[t]*y; p=x; //int k=gcd(p,q); x=q; y=p; }}int main(){//freopen("t.txt","r",stdin); int t; scanf("%d",&t); for(int p=1;p<=t;p++){ printf("Case #%d: ",p); scanf("%d",&n); a[0]=0; b[0]=1; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } for(int i=1;i<=n;i++){ scanf("%d",&b[i]); } int x,y; dfs(x,y,1); int k=gcd(x,y); printf("%d %d\n",x/k,y/k); } return 0;}
0 0
- HDU 5912 Fraction (2016-ccpc-长春)
- HDOJ 5912 Fraction 【2016CCPC长春现场赛】数学
- 2016中国大学生程序设计竞赛(ccpc 长春) Fraction【模拟】
- HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))
- hdu 5912 Fraction 2016中国大学生程序设计竞赛(长春) 水题
- hdu 5912 Fraction -2016中国大学生程序设计竞赛(长春)
- CCPC[长春] 2.Fraction 手动模拟
- HDU 5914 Triangle (2016-ccpc-长春)
- 2016 ccpc 长春站
- HDU 5912 Fraction【模拟】(2016中国大学生程序设计竞赛(长春)B题)
- HDU 5912 Fraction 模拟题 【2016中国大学生程序设计竞赛(长春)】
- HDU Fraction 2016中国大学生程序设计竞赛(长春)-重现赛
- hdu 5912 Fractionl 2016ACM/CCPC长春赛区现场赛B
- 2016 ccpc长春现场赛I Sequence I(hdu 5918)
- 2016 ccpc长春现场赛J Sequence II(hdu 5919)
- HDU 5916 Harmonic Value Description (2016-ccpc-长春)
- HDU 5918 Sequence I (2016-ccpc-长春)
- 2016--CCPC--长春站总结
- poj_2240 Arbitrage(Bellman_ford + map)
- 和哥一起学java之java学习大纲
- 百度云服务器搭建java+tomcat+mysql
- Struts2接收传递的参数
- UESTC - 1251 谕神的密码(DP)
- HDU 5912 Fraction (2016-ccpc-长春)
- PHP连接SqlServer2000/2005设置
- Java 反射学习要点(一)
- java插入排序
- static关键字的用法
- Sally配置文件讲解
- PHP中MySQL、MySQLi和PDO的用法和区别
- CuratorFramework节点监听一 PathChildrenCache
- app:transformClassesWithJarMergingForDebug报错