Codeforces 483B - Friends and Presents(二分)
来源:互联网 发布:南京java培训 知乎 编辑:程序博客网 时间:2024/05/02 13:39
又是一道涨姿势的题目
这个同学解释的很好,附链接:http://www.cnblogs.com/windysai/p/4058235.html
画个韦恩图的话就很直观了
#include <iostream>#include <cstdio>#include <cmath>using namespace std;typedef long long LL;#define maxn 1e18LL cnt1,cnt2,x,y;bool solve(LL m){LL f1=m/x; //能被x整除的数的个数LL f2=m/y; //能被y整除的数的个数LL both=m/(x*y); //既能被y也能被x整除的数的个数LL others=m-f1-f2+both; //不能被y也不能被x整除的数的个数LL ff1=f1-both; //只能被f1整除的数的个数LL ff2=f2-both; //只能被f2整除的数的个数LL gf1=(cnt1-ff2>=0 ? cnt1-ff2 : 0); //在others里能选择出可以给第一个人的数的数字个数LL gf2=(cnt2-ff1>=0 ? cnt2-ff1 : 0); //在others里能选择出可以给第二个人的数的数字个数return (gf1+gf2<=others);}int main(){while(cin>>cnt1>>cnt2>>x>>y){LL l=1,r=1e18;while(l<r){LL m=(l+r)>>1;if(solve(m))r=m;elsel=m+1;}cout<<r<<endl;}return 0;}
0 0
- codeforces 483b Friends and Presents 二分
- CodeForces-483B Friends and Presents(二分)
- Codeforces 483B - Friends and Presents(二分)
- codeforces #483B# Friends and Presents(二分+math)
- Codeforces 483B Friends and Presents(二分+数论)
- Codeforces 483B. Friends and Presents 二分查找
- Codeforces 483B Friends and Presents【二分+数论】涨姿势~~~
- CodeForces 483B Friends and Presents(二分+容斥定理)
- codeforces 483B Friends and Presents
- CodeForces - 483B Friends and Presents
- codeforces 483B. Friends and Presents
- 【CODEFORCES】 B. Friends and Presents
- Codeforces Round #275(Div2) B.Friends and Presents 二分+数学
- [Codeforces #275 (Div. 2)B. Friends and Presents] 二分
- Codeforces #275 (Div. 2) B - Friends and Presents(二分大法好)
- Review of codeforces 483B Friends and Presents
- B. Friends and Presents
- CF_483B Friends and Presents(二分)
- ios即时通讯客户端开发之-mac上搭建openfire服务器
- 超棒的30款JS类库和工具
- AppScan9.0
- Eclipse闪退后,关于Tomcat服务器端口被占用的问题。
- ios即时通讯客户端开发之-mac上安装MySQL
- Codeforces 483B - Friends and Presents(二分)
- hive三种访问方式
- 判断三角形
- PHP留言板
- 关于王小云破解MD5
- 积跬步,聚小流-------那第一个程序得到了啥
- ACM小技巧
- POJ1182 食物链
- C 中的strcpy 和strncpy