问题 F: AtCoDeer and Election Report
时间限制: 1 Sec 内存限制: 128 MB提交: 345 解决: 91
[ 提交][ 状态][ 讨论版][命题人: 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.
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
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.
题意:随着时间给出选票的比例,最后选票数的总和是多少。
分析:比例与实际选票之间存在一个倍数关系,用ans1,ans2代表两个选票的数量,并把初始值都设成1,每次分别除以各自的比例不能整数就+1,这样再取两者中除完之后结果大的那一个,再令a,b分别乘以这个倍数,则为当前选票数。
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
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;}
int main()
{
ll n,ans1=0,ans2=0,i;
ll a,b,t,m;
scanf("%lld",&n);
ans1=1;
ans2=1;
for(i=1;i<=n;i++)
{
scanf("%lld%lld",&a,&b);
t=1;
if(ans1>a)
{
t=ans1/a;
if(ans1%a!=0)
t++;
}
if(ans2>b)
{
m=ans2/b;
if(ans2%b!=0)
m++;
t=max(t,m);
}
ans1=a*t;
ans2=b*t;
}
printf("%lld\n",ans1+ans2);
return 0;
}