【codeforces 483B】Friends and Presents
【链接】 我是链接,点我呀:)
【题意】
【题解】
我们可以二分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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 793D】Presents in Bankopolis
[题目链接]:http://codeforces.com/contest/793/problem/D [题意] 给你n个点, 这n个点 从左到右1..n依序排; 然后给你m条有向边; 然后让你从中选出 ...
- 【codeforces 764B】Timofey and cubes
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- iOS 基础类解析 - NSString、NSMutableString
iOS 基础类解析 - NSString 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 ...
- thymeleaf+springboot找不到html,只返回了字符串
在浏览器用链接http://localhost:8080/city/page/list 访问时页面上只出现了cityList字样,预期是返回cityList.html 解决:在controller中使 ...
- HDU 5289 Assignment (ST算法区间最值+二分)
题目链接:pid=5289">http://acm.hdu.edu.cn/showproblem.php?pid=5289 题面: Assignment Time Limit: 400 ...
- jabberNet 修改花名册条目的昵称
修改昵称,这么简单的功能,在jabberNet里怎么实现? 翻遍了jabberNet里的代码,jabber.client.RosterManager也,JabberClient也,似乎都没有现成的方法 ...
- oc43--野指针和空指针
// // main.m // 野指针和空指针 #import <Foundation/Foundation.h> #import "Person.h" int mai ...
- bzoj 1800 & 洛谷 P2165 [AHOI2009]飞行棋 —— 模拟
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1800 https://www.luogu.org/problemnew/show/P21 ...
- SpringMVC使用POST方法传递数据,却出现Request method 'GET' not supported?
转自:https://segmentfault.com/q/1010000011245770 问题:没有使用get获取当前页面解决方案: @RequestMapping(value = " ...
- python 46 css组合选择器 及优先级 、属性选择器
一:css组合选择器 特性:每个选择器位可以为任意基本选择器或选择器组合 选择器分为以下几类: 群组选择器,子代(后代)选择器,相邻(兄弟)选择器,交集选择器,多类名选择器 1.群组选择器: d ...
- set()集合的概念与一般操作
1.概念 set集合是python的一种基本数据类型,其特点为: 1.元素不重复(可以利用这条性质除去重复元素) 2.在集合中无序 3.元素可hash(int,str,bool,tuple) set集 ...
- TYVJ 1288 飘飘乎居士取能量块
背景 9月21日,pink生日:9月22日,lina生日:9月23日,轮到到飘飘乎居士(狂欢吧,(^__^) 嘻嘻--). 描述 9月21日,今天是pink的生日,飘飘乎居士当然要去别人的领土大闹一番 ...