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

  • 相关阅读:
    2019/2/3从字符串中删除指定的字符
    2019/2/3求组合数
    2019/2/3统计各成绩段的学生人数
    2019/2/3摄氏一华氏温度转换表
    2019/1/29有选择的复制字符串
    2019/1/28数字的移动
    2019/1/2810个整数的数据处理
    2019/1/27从三个数中找出最大的数(函数和宏)
    2019/1/23编写函数统计字符串中字母、数字、空格和其它字符的个数
    Jenkins 执行python脚本
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9085190.html
Copyright © 2011-2022 走看看