码迷,mamicode.com
首页 > 其他好文 > 详细

AtCoDeer and Election Report

时间:2020-01-18 19:45:21      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:its   lin   following   prim   a*   check   比例   getc   har   

问题 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\n",sum1+sum2);
    return 0;
}

 

AtCoDeer and Election Report

标签:its   lin   following   prim   a*   check   比例   getc   har   

原文地址:https://www.cnblogs.com/lipu123/p/12209899.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!