AtcoderARC062Cくんと選挙速報AtCoDeer and Election Report思维

    xiaoxiao2022-07-04  186

     

    https://atcoder.jp/contests/arc062/tasks/arc062_a

     每次计算之前两个数,设为x,y,计算x/a,y/t,分别向上取整,取其中的最大值,再乘上a,t即可找到满足比例的最小的两个数

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define ll long long #define maxn 10005 using namespace std; int n; ll ans1,ans2; int main() { scanf("%d",&n); int a,t; scanf("%lld%lld",&ans1,&ans2); for(int i=1;i<n;i++) {ll num1,num2,num; scanf("%d%d",&a,&t); if(ans1%a==0) num1=ans1/a; else num1=ans1/a+1; if(ans2%t==0) num2=ans2/t; else num2=ans2/t+1; num=max(num1,num2); ans1=num*a; ans2=num*t; } printf("%lld\n",ans1+ans2); return 0; }

     

    最新回复(0)