问题 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=,f=;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-;for(;isdigit(c);c=getchar()) x=x*+c-'';return x*f;}
const int maxn=;
const int M=1e7+;
const int INF=0x3f3f3f3f;
int main()
{
ll n,sum1=,sum2=,i;
ll a,b,t,m;
cin>>n;
sum1=;
sum2=;
for(i=;i<=n;i++)
{
scanf("%lld%lld",&a,&b);
t=;
if(sum1>a)
{
t=sum1/a;
if(sum1%a!=)
t++;
}
if(sum2>b)
{
m=sum2/b;
if(sum2%b!=)
m++;
t=max(t,m);
}
sum1=a*t;
sum2=b*t;
}
printf("%lld\n",sum1+sum2);
return ;
}

最新文章

  1. C#开发微信门户及应用(4)--关注用户列表及详细信息管理
  2. Windows Live Writer测试
  3. LB(Load balance)负载均衡集群--{LVS-[NAT+DR]单实例实验+LVS+keeplived实验} 菜鸟入门级
  4. 推荐几个jQuery插件
  5. 增强for循环(forearch)
  6. Highcharts X轴名称太长,如何设置下面这种样式
  7. 我对Padding Oracle Attack的分析和思考
  8. Java for LeetCode 048 Rotate Image
  9. phalcon: 过滤(Phalcon\Filter())
  10. 为什么要使用jQuery?
  11. 自定义Filter服务
  12. 原生态JS实现banner图的常用所有功能
  13. Git Flow Note
  14. windows系统,优化C盘空间的方法
  15. 从头编写 asp.net core 2.0 web api 基础框架 (4) EF配置
  16. Token认证来龙去脉
  17. 2.7 C++构造函数
  18. jmeter 读取excel数据
  19. 【知识笔记】Debugging
  20. Redis 通用操作1

热门文章

  1. 在多租户(容器)数据库中如何创建PDB:方法4 克隆远程Non-CDB
  2. FLV格式解析(转)
  3. 第二篇,前端高性能JavaScript优化
  4. OpenCV离散傅里叶变换
  5. 题解【洛谷P1807】最长路_NOI导刊2010提高(07)
  6. 通过jquery将多选框变单选框
  7. TCL create list from file
  8. pandas 数据可视化之折线图
  9. Java学习笔记(十)面向对象---接口
  10. 【红黑树】的详细实现(C++)