生活随笔
收集整理的這篇文章主要介紹了
codeforces 483B Friends and Presents
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
http://codeforces.com/problemset/problem/483/B? ? ?
/*****************************************************************************
**** 題意:一個人有兩個 friends,需要將 a個不能整除 x 的數分給第一個friend,
**** b 個不能整除 y 的數分給第二個friend。x 和 y 都是素數來的。
**** 要求求出最小的 w,w表示可以從1,2,...,w 中取數。
**** 題解:二分查找【1,1e18】
*****************************************************************************/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
LL x,y,a,b;
bool check(LL w){LL x1 = w / x;LL x2 = w / y;LL B = w /(x * y);LL A = x1 - B;LL C = x2 - B;LL shengyu = w - A - B - C;LL a1 , b1;if(a > C) a1 = a - C;else a1 = 0;if(b > A) b1 = b - A;else b1 = 0;
// cout << shengyu << endl;if(shengyu >= a1 + b1) return true;return false;
}
int main(){cin >> a >> b >> x >> y;LL l = 1,r = 1e18;
// cout << r << endl;LL mid;while(l < r){mid = (l + r ) / 2;if(check(mid)) r = mid;else l = mid + 1;}cout << r << endl;
}
與50位技術專家面對面20年技術見證,附贈技術全景圖
總結
以上是生活随笔為你收集整理的codeforces 483B Friends and Presents的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。