zoukankan      html  css  js  c++  java
  • AtCoDeer and Election Report

    问题 F: AtCoDeer and Election Report

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 200  解决: 52
    [提交][状态][讨论版][命题人:admin]

    题目描述

    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.

    样例输入

    3
    2 3
    1 1
    3 2
    

    样例输出

    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.

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
        long long int n;
        scanf("%lld",&n);
        long long int a,b;
        long long int x,y;
        a = 1,b = 1;
        for(int i=0;i<n;i++)
        {
            scanf("%lld %lld",&x,&y);
            long long int t,t1,t2;
            t1 = 1;
            t2 = 1;
            t = 1;
            if(x>=a)
            {
                ;
            }
            else
            {
                t1 = a/x;
                if(a%x!=0)
                    t1++;
                //t1 = ceil(a*1.0/x);
            }
            if(y>=b)
            {
               ;
            }
            else
            {
                t2 = b/y;
                if(b%y!=0)
                    t2++;
               // t2 = ceil(b*1.0/y);
            }
            t = max(t1,t2);
            a = x*t;
            b = y*t;
        }
        long long int ans = a+b;
        printf("%lld",ans);
    }

    //要让a,b其中一个加上某个数成为x,y的t倍   需要求的只有这个t

  • 相关阅读:
    Codeforces Round #595 (Div. 3) A,B,C,D
    计算几何板子题【2019牛客国庆集训派对day7——三角形和矩形】【多边形相交的面积】
    [POJ]POJ1753(dfs)
    [POJ]POJ2965(dfs)
    洛谷 P1772 [ZJOI2006]物流运输 题解
    简单概率与期望
    洛谷 P3802 小魔女帕琪 题解
    用树状数组实现的平衡树
    【模板】扩展中国剩余定理(EXCRT)
    新博客开通通知
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9085190.html
Copyright © 2011-2022 走看看