【链接】 我是链接,点我呀:)

【题意】

【题解】

我们可以二分n的值,设为mid
那么对于n=mid
我们可以算出来以下3个东西
temp1 = n/x;
temp2 = n/y;
temp3 = n/lcm(x,y);//lc(x,y)表示x和y的最小公倍数
temp1是第一个人在1..n中不喜欢的数的个数
temp2是第二个人在1..n中不喜欢的数的个数
temp3是两个人在1..n中都不喜欢的数的个数。
那么我们把1..n中temp1-temp3个第一个人不喜欢的数字全给第二个人
然后把1..n中temp2-temp3个第二个人不喜欢的数字全给第一个人
这样就能最大化地利用所有数字了。
然后
cnt[1]-=temp2-temp3
cnt[2]-=temp1-temp3
然后如果cnt[1]

【代码】

#include <bits/stdc++.h>
#define LL long long
using namespace std; const int N = 1e4; LL cnt[3],x,y; bool ok(LL v){
LL temp1 = v/x;
LL temp2 = v/y;
LL temp3 = v/(x*(y/__gcd(x,y)));
LL tc1 = cnt[1],tc2 = cnt[2];
tc1-=(temp2-temp3);
tc2-=(temp1-temp3);
if (tc1<0) tc1 = 0;
if (tc2<0) tc2 = 0;
LL rest = v-temp1-temp2+temp3;
if (tc1+tc2<=rest) return true;
return false;
} int main()
{
//freopen("D:\\rush.txt","r",stdin);
ios::sync_with_stdio(0),cin.tie(0);
cin >> cnt[1] >> cnt[2] >> x >> y;
LL l = 1,r = 1e10,temp = -1;
while(l<=r){
LL mid = (l+r)>>1;
if (ok(mid)){
temp = mid;
r = mid - 1;
}else l = mid + 1;
}
cout<<temp<<endl;
return 0;
}

【codeforces 483B】Friends and Presents的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 793D】Presents in Bankopolis

    [题目链接]:http://codeforces.com/contest/793/problem/D [题意] 给你n个点, 这n个点 从左到右1..n依序排; 然后给你m条有向边; 然后让你从中选出 ...

  3. 【codeforces 764B】Timofey and cubes

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. ios 视频播放代码Demo

    方法一: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. / ...

  2. 编程算法 - 和为s的连续正整数序列 代码(C)

    和为s的连续正整数序列 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 输入一个正数s, 打印出全部和为s的连续正数序列(至少含有两个数). 起 ...

  3. CentOS 安装 MRTG 软件完成后的 403 Forbidden(转载)

    用 yum 安装 MRTG 並设定好之后也把 apache 的 httpd.conf 加上 mrtg 的目录,但 http://server/mrtg 卻一直出現 403 Forbidden.在 ht ...

  4. C++对象内存布局 (一)

    一.前言 在看了皓哥的C++对象的布局之后:http://blog.csdn.net/haoel/article/details/3081328.感觉自己还是总是不能记得很清楚,故在此总结一下C++对 ...

  5. android自定义dialog中点击listview的item事件关闭dialog

    import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; ...

  6. C# datagridview 删除行(转 学会、放弃博客)

    原文引入:http://zhangyanyansy.blog.163.com/blog/static/13530509720106171252978/ datagridview 删除行 2010-07 ...

  7. PCB Genesis加二维码 实现方式

    使用incam可以很轻松的增加2维码,这里通过另外一种方式玩转二维码的加法, 使用谷歌zxing.dll类库实现,将文字信息转为bitmap点阵后,在Genesis绘制点即可. 一.incam增加二维 ...

  8. JavaScript学习杂记

    1.DOM层级:document(document) --> doctype,documentElement(html) --> head,body(body). 2.offset, cl ...

  9. python-day01 pip 在线安装,标识符规则,注释,变量名,类型

    1.python第三方库安装: 在线安装:pip install 库名 pip install 库名 -i 国内源网站地址 离线安装:xxx.tar.gz/rar/zip 解压安装 2.标识符规则: ...

  10. 使用logback实现http请求日志导入mongodb

    spring boot自带logback作为其日志新系统,但是在实际工作中,常常需要对日志进行管理或分析,如果只是单纯的将日志导入文本文件,则在查询时操作过于繁琐,如果将其导入mysql等关系型数据库 ...