CCPC2016长春B (hdu 5912 Fraction)

water

//#define test
#include<bits/stdc++.h>
using namespace std;
const int Nmax=1e6+7;
typedef long long ll;
struct LL
{
    ll a,b;
    LL(){ }
    LL(ll aa,ll bb){
        a=aa,b=bb;
        ll g=__gcd(a,b);
        a/=g;
        b/=g;
    }
    friend LL operator + (const LL &a,const LL &b)
    {
        ll t2=a.b*b.b, t1=a.a*b.b+a.b*b.a;
        return LL(t1,t2);
    }
    friend LL operator + (const ll &a,const LL &b)
    {
        ll t1=a*b.b+b.a;
        return LL(t1,b.b);
    }
    friend LL operator / (const ll &a,const LL &b)
    {
        return LL(a*b.b,b.a);
    }

};
int n;
ll a[Nmax],b[Nmax];
int main()
{
    #ifdef test
    #endif
    int t;
    //freopen("b.in","r",stdin);
    scanf("%d",&t);
    for(int _=1;_<=t;_++)
    {
        LL ans(0,1);
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }
        for(int i=1;i<=n;i++)
            scanf("%lld",&b[i]);
        for(int i=n;i>=1;i--)
        {
            ans=b[i]/(a[i]+ans);
        }
        printf("Case #%d: ",_);
        printf("%lld %lld\n",ans.a,ans.b);
    }

    return 0;
}

原文地址:https://www.cnblogs.com/LMissher/p/9673981.html

时间: 2024-10-10 12:30:33

CCPC2016长春B (hdu 5912 Fraction)的相关文章

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 ide

HDU 5912 Fraction(模拟——分子式化简求解)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5912 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, c

CCPC2016长春F (hdu 5916 Harmonic Value Description)

构造一个n个数字的排列,使其作为 sigma( gcd( a[i] , a[i+1] ) ) 中第k小的排列. 因为题目给的 k*2 <= n ,所以可以知道只会询问最小到第 n/2 小,易得最多移动一个数字即可得到答案. 假设原始排列为1 2 3 ... n,如果询问最小直接输出排列,否则询问x且x是偶数就把x移动到2*n与2*n-1之间. 如果x是奇数就将x与 2*n-1或者2*n+1交换.因为有可能2*n-1和2*n+1与x-1或者x+1不互质. //#define test #inclu

CCPC2016长春D (hdu 5914 Triangle)

water,给一个数n,问从1...n的数字里最少删去多少数字让剩下的数字必不可能组成三角形. 保留的数字必定是1.2.3.5.8.13.21.....这样的数字. //#define test #include<bits/stdc++.h> using namespace std; const int Nmax=1e6+7; typedef long long ll; int _,n; int f[10],cas=1; int main() { #ifdef test #endif // f

HDU - 4813 Hard Code (长春赛区水题)

Description Some strange code is sent to Da Shan High School. It's said to be the prophet's note. The note is extremely hard to understand. However, Professor Meng is so smart that he successfully found the pattern of the code. That is, the length of

HDU - 4814 Golden Radio Base (长春赛区B题)

最小二乘法又叫做最小平方法,是一种数学优化技术.它通过最小化误差的平方和寻找数据的最佳函数匹配. 通常情况下最小二乘法用于求回归问题.以简单的线性最小二乘为例,二维平面上给定个点的坐标,确定一条直线, 要求大致符合这个点的走向. 我们可以设这条直线的方程为,那么就要使在处的函数值与给定的值相 差达到最小,也就是说,要确定的值,使得 最小.根据这种方法求的值就是典型的最小二乘法. 可以看出是的一个二元函数,要求的最小值,那么求偏导,有 进一步得到 然后联立两式可以解出,如果方程数比较多,我们可以用

HDU 4815 2013长春现场赛C题

C - Little Tiger vs. Deep Monkey Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4815 Description A crowd of little animals is visiting a mysterious laboratory ? The Deep Lab of SYSU. "Are y

HDU - 3556 - Continued Fraction

先上题目: Continued Fraction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 332    Accepted Submission(s): 106 Problem Description Dumbear loves numbers very much.One day Dumbear found that each n

hdu 5438 Ponds(长春网络赛 拓扑+bfs)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5438 Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2237    Accepted Submission(s): 707 Problem Description Betty owns a lot of ponds, som