Mixed Dimensions Onsite Round will host N contestants this year.
Moath and Saif have been preparing the contest hall, Moath needs X minutes to set up a computer for the contest, while Saif needs Yminutes to set up a computer. Each one of them works separately on one computer at a time.
Hasan is concerned they won't finish setting up the PCs in time, can you help Hasan figure out the minimum time required by Moath and Saif to set up all N PCs for the contest?
Input
The input contains 3 integers, N, X, and Y (1 ≤ N, X, Y ≤ 109), the number of PCs to set up, the amount of minutes Moath needs to set up a computer, and the amount of minutes Saif needs to set up a computer, respectively.
Output
On a single line, print one integer, the minimum number of minutes required by Moath and Saif to set up all the PCs for the contest.
Examples
input
5 3 4
output
9
input
100 10 1
output
91
———————————————————————————————————————————————————————————— 说一说今天的雪崩经历……这道题是十分的令人崩溃啊,wa了23发终于过了好吧,堪称励志。
就是说有n个电脑,甲能a分钟修1个,乙能b分钟修一个,问最少多少时间修完
先拿到题看,嗯,容易啊,就是对于,反正ab一直在做,瞎搞搞就好了么,然后队友就给了我一个公式:n*a*b/(a+b),结果可想而知,爆int了。
然后发现了问题,改成longlong,然后就发现了最严重的问题……这个结果,double装不下……不下……下……
瞬间懵逼。
当时学弟还在车上,然后过来以后讲了下方法,事实上已经快要正确了,结果自己加了个特判……然后挖了个坑自己跳进去了。
悲剧啊……
————————————————————————————————————————————————————————————
嘛,这道题两种解法,一种是我们假设这个行为在某个时间结束,那么结束的时间总是固定的吧,然后我们假设在这个结束时间甲修了x个,那么乙就修了n-x,那公式是这样的:a*x=b(n-x),然后把这个方程式解出来,x可能是个小数,因为甲修完x个的时候可能乙没东西修了,但是从公式上来说乙是要修到一半的。
那么有了这个小数,问题就变成了最后一个东西是甲修还是乙修,讨论一下就好了
第二种解法比较计算机思维,就是既然放不下,那我也不放了,直接用二分搜索查找答案,250ms,log2 (1023)的复杂度也不过23/log102,轻松愉快的就找到了目标,当然过程得讨论一下,就是如果当前的时间是够的,那么rig=mid,如果当前不够,就lef=mid+1,这样最终会变成lef==rig的情况,然后直接输出就好啦。
——————————————————————code version 1——————————————————————————————
#include<cstdio> #include<iostream> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> #include<string> #include<map> #include<queue> #include<vector> #define V 100+10 #define E 10000+10 #define ll long long const int INF=0x3f3f3f3f; using namespace std; ll mina=INF,shi; int main() { ll n; ll a,b,c,d; ll x,y; cin>>n>>a>>b; c=min(a,b);d=max(a,b); /*if(d==c){ if(n%2==0)cout<<n*c/2<<endl; else cout<<(n/2+1)*c<<endl; }*/ y=d*n/(c+d)+1; if(y>n)cout<<c*n<<endl; else { for(x=y;x>=0;x--){ if(c*x<d*(n-x)){ mina=min(c*(x+1),d*(n-x)); break; } } cout<<mina<<endl; } }
————————————————————version 2—————————————————————————————————
#include<stdio.h> #include<string.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<queue> #include<climits> #include<map> #include<stack> #include<list> #define file_in freopen("input.txt","r",stdin) #define MAX 8000 #define HASH 100019 using namespace std; #define ll long long #define FF(x,y) for(int i=x;i<y;i++) int main() { ll n, a, b; cin >> n >> a >> b; ll lef = 1; ll rig = 1e23; while (1) { ll mid = (lef + rig) >> 1; if (mid / a + mid / b >= n){ rig = mid; } else { lef = mid+1; } if (lef >= rig) { cout << lef << endl; return 0; } } }