首页 > 代码库 > HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))

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): 0


Problem Description
Mr. 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?
 

 

Input
The 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 (n8).

The second line contains n integers: a1,a2,?an(1ai10).
The third line contains n integers: b1,b2,?,bn(1bi10).
 

 

Output
For 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 Input
121 12 3
 

 

Sample Output
Case #1: 1 2
Hint
Here are the details for the first sample:2/(1+3/1) = 1/2
 

 

Statistic | Submit | Clarifications | Back

 

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5912

题目大意:

  给你一个分式,如图,求化简后的分子分母(不含公约数)。

  技术分享

题目思路:

  【模拟】

  因为n只有10,可以直接模拟。

 

技术分享
 1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<algorithm> 6 #include<string> 7 #include<iomanip> 8 #include<map> 9 #include<stack>10 #include<queue>11 #include<set>12 #include<bitset>13 #include<memory.h>14 #include<time.h>15 #include<stdio.h>16 #include<stdlib.h>17 #include<string.h>18 //#include<stdbool.h>19 #include<math.h>20 #define min(a,b) ((a)<(b)?(a):(b))21 #define max(a,b) ((a)>(b)?(a):(b))22 #define abs(a) ((a)>0?(a):(-(a)))23 #define lowbit(a) (a&(-a))24 #define sqr(a) ((a)*(a))25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))26 #define mem(a,b) memset(a,b,sizeof(a))27 #define eps (1e-10)28 #define J 1029 #define mod 100000000730 #define MAX 0x7f7f7f7f31 #define PI 3.1415926535897932332 #pragma comment(linker,"/STACK:1024000000,1024000000")33 #define N 200434 using namespace std;35 typedef long long LL;36 double anss;37 LL aans,sum;38 int cas,cass;39 int n,m,lll,ans;40 int a[N],b[N];41 int gcd(int a,int b)42 {43     if(!b)return a;44     return gcd(b,a%b);45 }46 int main()47 {48     #ifndef ONLINE_JUDGEW49 //    freopen("1.txt","r",stdin);50 //    freopen("2.txt","w",stdout);51     #endif52     int i,j,k;53 //    init();54 //    for(scanf("%d",&cass);cass;cass--)55     for(scanf("%d",&cas),cass=1;cass<=cas;cass++)56 //    while(~scanf("%s",s))57 //    while(~scanf("%d",&n))58     {59         scanf("%d",&n);60         for(i=1;i<=n;i++)scanf("%d",&a[i]);61         for(i=1;i<=n;i++)scanf("%d",&b[i]);62         int fz=b[n],fm=a[n];63         for(i=n-1;i;i--)64         {65             fz+=a[i]*fm;66             fm*=b[i];67             swap(fz,fm);68         }69         i=gcd(fz,fm);70         fz/=i,fm/=i;71         printf("Case #%d: ",cass);72         printf("%d %d\n",fz,fm);73     }74     return 0;75 }76 /*77 //78 79 //80 */
View Code

 

HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))