HDU 5912 Fraction (模拟)
题意:给定一个分式,让你化简。
析:从分母开始模拟分数的算法,最后约分。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[10], b[10]; int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d", &n);
a[0] = 0;
for(int i = 1; i <= n; ++i) scanf("%d", a+i);
for(int i = 1; i <= n; ++i) scanf("%d", b+i); int p = a[n], q = 1;
for(int i = n; i > 0; --i){
int pp = b[i] * q + p * a[i-1];
q = p;
p = pp;
} int g = __gcd(p, q);
p = p / g;
q = q / g;
printf("Case #%d: %d %d\n", kase, p, q);
}
return 0;
}
HDU 5912 Fraction (模拟)的更多相关文章
- 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 5912 Fraction(模拟)
Problem Description Mr. Frog recently studied how to add two fractions up, and he came up with an ev ...
- HDU 5912 Fraction
题目来源:2016 CCPC 长春站 题意:青蛙先生想计算一个式子的值,输入两个数列a[],b[]求出最后的分子和分母 思路:一开始看到这个图片首先想到的是递归实现,递归部分始终计算的是右下部分 /* ...
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- hdu 4740【模拟+深搜】.cpp
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...
- HDU 2568[前进]模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...
- hdu 4964 恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...
随机推荐
- 移动web页面字体大小三
<script type="text/javascript"> (function (doc, win) { var docEl = doc.documentEleme ...
- Piggy-Bank--hdu1114(完全背包)
http://acm.hdu.edu.cn/showproblem.php?pid=1114 Problem Description Before ACM can do anything, a bud ...
- Borg Maze-POJ3026(bfs+最小生成树)
http://poj.org/problem?id=3026 如果一个一个普通搜处理不好的话会超时 可以连到一块搜 我觉得这个方法特别好 #include<stdio.h> #inclu ...
- Java课堂测试--实现ATM的基本操作体会
9月20的周四的Java课堂第一节课上就是有关于实现ATM的考试内容,在实现的过程中我了解到自己本身还是有很多的不足之处,例如在实现工程方面的相似性上面还有些许就的欠缺,再者就是回宿舍拿电源的原因导致 ...
- ABP每次生成前都执行bundle设置
ABP项目每次编译mvc项目时都会执行bundle,比较耗时. 可以在项目文件(*.csproj)中发现设置了每前生成前执行的命令 <Target Name="PreBuild&quo ...
- Spring事务管理概述
以下内容引用自http://wiki.jikexueyuan.com/project/spring/transaction-management.html: 数据库事务是一个被视为单一的工作单元的操作 ...
- 主成分分析(principal components analysis)
http://www.cnblogs.com/jerrylead/tag/Machine%20Learning/ PCA的思想是将n维特征映射到k维上(k<n),这k维是全新的正交特征.这k维特 ...
- db2安装配置备份还原
环境 cenos 7.0 db2版本 db2_v101_linuxx64_expc.tar 安装db2 解压db2 tar zxvf db2_v101_linuxx64_expc.tar cd exp ...
- Android 通过ADB Wireless无线调试应用
使用数据线调试应用难免不方便,本篇博客介绍使用ADB Wireless工具.当手机和电脑处在同一网络下.实现无线调试应用. ADB Wireless可以让手机用无线来代替USB连接.而使用ADB工具的 ...
- Javascript调试命令
Javascript调试命令——你只会Console.log() ? Console 对象提供对浏览器控制台的接入(如:Firefox 的 Web Console).不同浏览器上它的工作方式是不一样的 ...