Codeforces Round #275 (Div. 2) --B Friends and Presents
2014-10-26 20:06
411 查看
题意:
有两个朋友B和C,B和C都很喜欢数字,现在A要送给他们各自一些不同的数字来做礼物,但是B不喜欢素数x,所以不能送给他x的倍数;同样如此,C不喜欢素数y,也不能送给他y的倍数。现在的任务是从找到一个最小的数v,使得从1~v里面可以满足A的要求,分别送给B和C。
(题意来自:http://blog.csdn.net/u013446688/article/details/40455181,233)
思路:二分= =,总是想不到二分这个东西。。所以不常写,所以写完就错了= =,浮点数二分还好。。整形的二分总是写蒙,l+1和r-1什么的搞不懂,但是看别人的还能看懂。。。还是多写多练= =。。
这道题要让最大值最小,这种东西一般都是二分,我原来写过这句话(从某处借鉴来的=。=),但是现在依旧没想到,所以再写一遍。。
代码:
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
int n, m, x, y;
cin>>n>>m>>x>>y;
int l = 1, r = 2e9;
while(l < r){
int mid = l + (r - l)/2;///这个地方貌似很重要的样子。。
if(n<=(mid - mid/x)&&m<=(mid - mid/y)&&n+m<=(mid - mid/(x*y)))
r = mid;
else l = mid + 1;
}
printf("%d\n", r);
return 0;
}
有两个朋友B和C,B和C都很喜欢数字,现在A要送给他们各自一些不同的数字来做礼物,但是B不喜欢素数x,所以不能送给他x的倍数;同样如此,C不喜欢素数y,也不能送给他y的倍数。现在的任务是从找到一个最小的数v,使得从1~v里面可以满足A的要求,分别送给B和C。
(题意来自:http://blog.csdn.net/u013446688/article/details/40455181,233)
思路:二分= =,总是想不到二分这个东西。。所以不常写,所以写完就错了= =,浮点数二分还好。。整形的二分总是写蒙,l+1和r-1什么的搞不懂,但是看别人的还能看懂。。。还是多写多练= =。。
这道题要让最大值最小,这种东西一般都是二分,我原来写过这句话(从某处借鉴来的=。=),但是现在依旧没想到,所以再写一遍。。
代码:
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
int n, m, x, y;
cin>>n>>m>>x>>y;
int l = 1, r = 2e9;
while(l < r){
int mid = l + (r - l)/2;///这个地方貌似很重要的样子。。
if(n<=(mid - mid/x)&&m<=(mid - mid/y)&&n+m<=(mid - mid/(x*y)))
r = mid;
else l = mid + 1;
}
printf("%d\n", r);
return 0;
}
相关文章推荐
- Codeforces Round #275 (Div. 2)-B. Friends and Presents
- B. Friends and Presents(Codeforces Round #275(div2)
- Codeforces Round #275 (Div. 2)B——Friends and Presents
- Codeforces Round #275 (Div. 2) B. Friends and Presents
- Codeforces Round #275 (Div. 2) --B Friends and Presents
- B. Friends and Presents(Codeforces Round #275(div2)
- B. Friends and Presents(Codeforces Round #275(div2)
- Codeforces Round #275 (Div. 2) B Friends and Presents
- Codeforces #275 (Div. 2) B - Friends and Presents(二分大法好)
- [Codeforces Round #275 (Div. 2)]B - Friends and Presents
- Codeforces Round #275 (Div. 2) B. Friends and Presents 二分+数学
- [Codeforces #275 (Div. 2)B. Friends and Presents] 二分
- Codeforces Round #394 (Div. 2) B. Dasha and friends(暴力)
- VK Cup 2016 - Round 1 (Div. 2 Edition)-B - Bear and Displayed Friends-STL(维护前k大)
- Codeforces483B——二分——Friends and Presents
- Codeforces Round #361 (Div. 2) D. Friends and Subsequences
- Codeforces Round #305 (Div. 1)E. Mike and Friends【后缀数组+线段树】
- Codeforces Round #179 (Div. 1) C. Greg and Friends(BFS 或者最短路)
- Codeforces Round #361 (Div. 2) D. Friends and Subsequences 二分
- B. Friends and Presents