HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))
Fraction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0Problem DescriptionMr. 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?
InputThe 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).OutputFor 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 Input1
2
1 1
2 3Sample OutputCase #1: 1 2HintHere are the details for the first sample:
2/(1+3/1) = 1/2Statistic | Submit | Clarifications | Back
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5912
题目大意:
给你一个分式,如图,求化简后的分子分母(不含公约数)。

题目思路:
【模拟】
因为n只有10,可以直接模拟。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 2004
using namespace std;
typedef long long LL;
double anss;
LL aans,sum;
int cas,cass;
int n,m,lll,ans;
int a[N],b[N];
int gcd(int a,int b)
{
if(!b)return a;
return gcd(b,a%b);
}
int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
scanf("%d",&n);
for(i=;i<=n;i++)scanf("%d",&a[i]);
for(i=;i<=n;i++)scanf("%d",&b[i]);
int fz=b[n],fm=a[n];
for(i=n-;i;i--)
{
fz+=a[i]*fm;
fm*=b[i];
swap(fz,fm);
}
i=gcd(fz,fm);
fz/=i,fm/=i;
printf("Case #%d: ",cass);
printf("%d %d\n",fz,fm);
}
return ;
}
/*
// //
*/
HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))的更多相关文章
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))
Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...
- HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛
思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...
- 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5920 我们的思路是: 对于一个串s,先根据s串前一半复制到后一半构成一个回文串, 如果这个回文串比s小, ...
- 2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1004 Danganronpa
Problem Description Chisa Yukizome works as a teacher in the school. She prepares many gifts, which ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1011 Lweb and String
Problem Description Lweb has a string S. Oneday, he decided to transform this string to a new sequen ...
随机推荐
- 总结如何实现Android浮动层,主要是dialog的使用
自定义一个类继承自Dialog类,然后在构造方法中,定义这个dialog的布局和一些初始化信息. 查看源码打印? 01 public class MenuDialog extends Dialog { ...
- css动画结束后 js无法修改translated值 .
由于项目的需要,俺要做一些页面的转场动画. 即将是移动端,肯定是首先css动画了. 结果确发现,css动画中,如果设置animation-fill-mode: both;在动画结束后无法个性trans ...
- JavaScript+DOM编程艺术【读书笔记】
第四章笔记: 如何让一个a标签不跳转: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www. ...
- Codeforces 551D GukiZ and Binary Operations(矩阵快速幂)
Problem D. GukiZ and Binary Operations Solution 一位一位考虑,就是求一个二进制序列有连续的1的种类数和没有连续的1的种类数. 没有连续的1的二进制序列的 ...
- jQuery仿苏宁易购导航
最近看了些网上的各类导航网站源码,自己学习制作了一个仿苏宁易购的导航栏 jQuery部分代码 $(function(){ $(".CategoryTree>ul>li" ...
- Gtest打桩函数
假设Client的定义如下 class Client { ...... public: virtual bool GetData(std::string& data); ...... }; 我 ...
- js学习--DOM操作详解大全一(浏览器对象)
一.客户端中的window对象 window对象表示当前浏览器的窗口,它是一个顶级对象,我们创建的所有对象.函数.变量都是window对象的成员. window对象自带了一些非常有用的方法.属性. w ...
- css3多行省略号
-webkit-line-clamp 概述: -webkit-line-clamp 是一个 不规范的属性(unsupported WebKit property),它没有出现在 CSS 规范草案中. ...
- 代码世界中的Lambda
“ λ ”像一个双手插兜儿,独自行走的人,有“失意.无奈.孤独”的感觉.λ 读作Lambda,是物理上的波长符号,放射学的衰变常数,线性代数中的特征值……在程序和代码的世界里,它代表了函数表达式,系统 ...
- 学渣也要搞 laravel(3)—— HTTP控制器
1. laravel 控制器在app/Http/Controllers/ 下,你会看到里面有一个Controller.php ,之后我们创建的控制器都是继承这个总控制器的.创建控制器只需要在这里面添加 ...