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

  • 相关阅读:
    数组(Array)的使用方法
    Django中的事务操作
    什么是事务(Transaction)?事务的四个特性以及事务的隔离级别
    0.2 Django + Uwsgi + Nginx 的生产环境部署之实战篇
    0.1 Django + Uwsgi + Nginx 的生产环境部署之理论篇
    linux 进入编辑文件,保存退出相关命令
    Django--restframework
    使用用户名/邮箱/手机号 + 密码登陆 多形式登陆
    Django中异步任务---django-celery
    Redis 常用命令
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9085190.html
Copyright © 2011-2022 走看看