B. Friends and Presents
来源:互联网 发布:机器人编程入门教程 编辑:程序博客网 时间:2024/05/10 21:11
http://codeforces.com/contest/483/problem/B
大致题意:给4个数,a,b,x,y,求最小的v,将v里的数分成两组,一组不是x的倍数,一组不是y的倍数,要求第一组里的数的个数要大于等于a,第二组的个数大于等于b。
方法:把是x的倍数的放到第二组,是y倍数的放到第一组,如果即使x的倍数又是y的倍数,就两组都不放,其他的随便放,用二分判断满不满足条件,二分的上限就是(a+b)*2+1
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int a, b, x, y;int judge(__int64 pp){ __int64 qq = (pp - pp/x - pp/y + pp/(x*y)); int cont1 = max(0, (int)(a-(pp/y-pp/(x*y)))); int cont2 = max(0, (int)(b-(pp/x-pp/(x*y)))); if(qq >= cont1+cont2) return 1; return 0;}__int64 solve(__int64 l, __int64 r){ __int64 res; while(l <= r){ __int64 mid = (l+r) / 2; if(judge(mid)){ res = mid; r = mid - 1; } else l = mid + 1; } return res;}int main(){ while(scanf("%d%d%d%d", &a, &b, &x, &y) == 4){ __int64 ans = solve(1, (a+b)*2+1); printf("%I64d\n", ans); } return 0;}
0 0
- B. Friends and Presents
- codefoeces B. Friends and Presents
- 【CODEFORCES】 B. Friends and Presents
- codeforces 483b Friends and Presents 二分
- codeforces 483B Friends and Presents
- CodeForces - 483B Friends and Presents
- codeforces 483B. Friends and Presents
- CF 275B. Friends and Presents
- CodeForces-483B 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 Round #275 (Div. 2) --B Friends and Presents
- Codeforces 483B - Friends and Presents(二分)
- Codeforces 483B Friends and Presents(二分+数论)
- Codeforces Round #275 (Div. 2) B. Friends and Presents
- Codeforces 483B. Friends and Presents 二分查找
- poj1753 枚举
- 快速排序算法及实现
- map与结构体结合使用
- group by 及 having 子句使用
- AJAX
- B. Friends and Presents
- 重定向 1>&2 2>&1
- 连续无空格英文字母或数字自动换行
- android初学------根据日期时间字符串返回date数据 获取年月日
- 织梦DedeCMS列表页、内页调用图集多张图片的方法
- <s:if>标签判断的使用
- hdoj problem 1211 RSA(快速幂求模算法)
- 第九周项目五填充一
- 快速排序