题意:
略
思路:
当时就想到用二分,但是二分的判断一直没想好,具体看代码吧。而且,看到好多人FST 第9组数据= =
二分的范围要注意。我直接右边的范围就设为10^9,结果就WA了。
注意使用long long;
code:
/* **********************************************
Created Time: 2014-10-25 14:58:22
File Name : cf.cpp
*********************************************** */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <fstream>
#include <cstring>
#include <climits>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long LL;
LL cot1, cot2, x, y;
bool charge(LL n)
{
LL t1 = n/x, t2 = n/y;
LL t3 = n/(x*y);
LL gx = n - t1 - t2 + t3;
LL c1 = cot1 - (t2-t3), c2 = cot2 - (t1-t3);
if(c1 > 0)
gx -= c1;
if(gx < 0)
return false;
if(c2 > 0)
gx -= c2;
if(gx < 0)
return false;
return true;
}
int main()
{
while(cin>>cot1>>cot2>>x>>y)
{
LL l = cot1+cot2, r = (LL)1e15;
LL ans = 0;
while(l <= r)
{
LL mid = (l+r)/2;
if(charge(mid))
{
ans = mid;
r = mid-1;
}
else
l = mid+1;
}
cout<<ans<<endl;
}
return 0;
}