zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Flink CEP实例及基础应用
    seata 分布式事务
    skywalking 分布式链路追踪
    datax 离线数据同步工具
    rocketmq 消息队列
    Nacos 服务注册
    跨站(cross-site)、跨域(cross-origin)、SameSite与XMLHttpRequest.withCredentials
    读写二进制文件与文本文件
    WPF中通过双击编辑DataGrid中Cell(附源码)
    记一次XML文件读取优化
  • 原文地址:https://www.cnblogs.com/lipu123/p/12209899.html
Copyright © 2011-2022 走看看