6473: AtCoDeer and Election Report(比例倍增)

6473: AtCoDeer and Election Report

时间限制: 1 Sec   内存限制: 128 MB
提交: 348   解决: 93
[ 提交][ 状态][ 讨论版][命题人: 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<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    long long n, a, b, x1, x2;
    scanf("%lld%lld%lld", &n, &a, &b);
    x1=a;x2=b;
    for(int i=0;i<n-1;i++)
    {
        scanf("%lld%lld", &a, &b);
        long long temp=x1/a;
        if(x1%a!=0)
            temp++;
        long long temp2=x2/b;
        if(x2%b!=0)
            temp2++;
        long long m=max(temp, temp2);
        x1=a*m;x2=b*m;
    }
    printf("%lld\n", x1+x2);
    return 0;
} 
/**************************************************************
    Problem: 6473
    User: ldu_reserver201701
    Language: C++
    Result: 正确
    Time:0 ms
    Memory:1092 kb
****************************************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hhjian6666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值