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;
    }
  • 相关阅读:
    软件升级细节卸载删除快捷方式等前需要检测
    安装gitlab的总结
    如何修改vagrant系统的root用户密码
    写一个PHP单例模式
    redis使用笔记
    mysql 删除商品名字重复数据,同时保留最新一条
    杀死僵尸进程
    Django 用户状态管理,认证,失效
    关于iOS多任务的一些扫盲
    ajax异步
  • 原文地址:https://www.cnblogs.com/lipu123/p/12209899.html
Copyright © 2011-2022 走看看