题目描述
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.
提示
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;
}