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 (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).

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

1
2
1 1
2 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 10
29 #define mod 1000000007
30 #define MAX 0x7f7f7f7f
31 #define PI 3.14159265358979323
32 #pragma comment(linker,"/STACK:1024000000,1024000000")
33 #define N 2004
34 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_JUDGEW
49 //    freopen("1.txt","r",stdin);
50 //    freopen("2.txt","w",stdout);
51     #endif
52     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 */

时间: 2024-11-08 19:23:53

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)Total Submission(s): 0    Accepted Submission(s): 0Special Judge Problem Description Everyone hates ugly problems. You are given a positive integer. You m

HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))

Triangle 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 has n sticks, whose lengths are 1,2, 3?n respectively. Wallice is a bad man,

HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))

Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0Special Judge Problem Description The harmonic value of the permutation p1,p2,?pn is ∑i=1

HDU 5833 Zhu and 772002(高斯消元)——2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 48    Accepted Submission(s): 16 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test the abili

HDU 5832 A water problem(取模~)—— 2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 60    Accepted Submission(s): 37 Problem Description Two planets named Haha and Xixi in the universe and they were created wit

2016中国大学生程序设计竞赛 - 网络选拔赛

solved 4/11 2016中国大学生程序设计竞赛 - 网络选拔赛

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 migic tree, the tree has N nodes , in each node , there is a treasure, it's value is V[i], and for each edge, there is a cost C[i], which means every time

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

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 fir

2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟

Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0Special Judge Problem Description Everyone hates ugly problems. You are given a positive integer. You m