• AtCoDeer and Election Report


    问题 G: AtCoDeer and Election Report

    时间限制: 1 Sec  内存限制: 128 MB
    [提交] [状态]

    题目描述

    AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≤i≤N) time, the ratio was Ti:Ai. It is known that each candidate had at least one vote when he checked the report for the first time.
    Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.

    Constraints
    1≤N≤1000
    1≤Ti,Ai≤1000(1≤i≤N)
    Ti and Ai (1≤i≤N) are coprime.
    It is guaranteed that the correct answer is at most 1018.

    输入

    The input is given from Standard Input in the following format:
    N
    T1 A1
    T2 A2
    :
    TN AN

    输出

    Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

    样例输入 Copy

    3
    2 3
    1 1
    3 2
    

    样例输出 Copy

    10
    

    提示

    When the numbers of votes obtained by the two candidates change as 2,3→3,3→6,4, the total number of votes at the end is 10, which is the minimum possible number.
     
    题意:就是两个人进行投票每一次都只显示投票比例
    AC代码:
    #pragma GCC optimize(2)
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;} 
    const int maxn=100000;
    const int M=1e7+10;
    const int INF=0x3f3f3f3f;
    int main()
    {
        ll n,sum1=0,sum2=0,i;
        ll a,b,t,m;
        cin>>n;
        sum1=1;
        sum2=1;
        for(i=1;i<=n;i++)
        {
            scanf("%lld%lld",&a,&b);
            t=1;
            if(sum1>a)
            {
               t=sum1/a;
               if(sum1%a!=0)
                    t++;
            }
            if(sum2>b)
            {
                m=sum2/b;
                if(sum2%b!=0)
                    m++;
                t=max(t,m);
            }
            sum1=a*t;
            sum2=b*t;
        }
        printf("%lld
    ",sum1+sum2);
        return 0;
    }
  • 相关阅读:
    .Net Core自动化部署系列(一):Jenkins + GitLab
    经典案例复盘——运维专家讲述如何实现K8S落地(摘抄)
    Quartz系列(一):基础介绍
    生产环境项目问题记录系列(二):同步方法调用异步方法
    微服务理论系列(一):服务发现四问四答(摘抄)
    Java中的继承、封装、多态的理解
    Java三大主流框架概述
    面试的技巧
    myBaits持久性框架
    MyBaits框架入门总结
  • 原文地址:https://www.cnblogs.com/lipu123/p/12209899.html
Copyright © 2020-2023  润新知