CodeForces 483B 二分答案
题目:
1 second
256 megabytes
standard input
standard output
You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.
Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.
A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.
The only line contains four positive integers cnt1, cnt2, x, y (1 ≤ cnt1, cnt2 < 109; cnt1 + cnt2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.
Print a single integer — the answer to the problem.
3 1 2 3
5
1 3 2 3
4
In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.
题解:
n-n/x-n/y+n/xy这一部分是两边都能用的,而n/y-n/xy是只能给x集合用的,n/x-n/xy是只能给y集合用的,先分配这两个,分配完之后剩下的再用n-n/x-n/y+n/xy里面的去填。满足条件的话就二分更小的,否则,二分更大的。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL; const LL maxn = 2e11; LL cnt1, cnt2, x, y; bool ok(LL n, LL t1, LL t2) {
t1 = t1 - (n / y - n / (x*y)); if (t1<) t1 = ;
t2 = t2 - (n / x - n / (x*y)); if (t2<) t2 = ;
if (n - n / x - n / y + n / (x*y) >= t1 + t2) return true;
return false;
} int main() {
// freopen("data_in.txt","r",stdin);
while (scanf("%lld%lld%lld%lld", &cnt1, &cnt2, &x, &y) == ) {
LL low = , hig = maxn;
//区间(low,hig]
while (low + <hig) {
LL mid = low + (hig - low) / ;
if (ok(mid, cnt1, cnt2)) {
hig = mid;
}
else {
low = mid;
}
}
printf("%lld\n", hig);
}
return ;
}
CodeForces 483B 二分答案的更多相关文章
- Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论
n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...
- codeforces 359D 二分答案+RMQ
上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{ ...
- Electric Charges CodeForces - 623C (二分答案)
大意: 平面上n个点每个点坐标为(x,0)或(0,y), 求任意两点距离平方最大值的最小值. 二分答案, 转化为判定最大值是否<=e, 按$x$排序后, 因为固定左端点, $y$绝对值的最大值是 ...
- Codeforces 1132D(二分答案+堆)
题面 传送门 分析 二分答案,考虑如何判定 可以用贪心的方法,每次找最快没电的电脑,在没电前1单位时间给它充电 正确性显然 实现上可以维护一个堆,存储每个电脑电用完的时刻,每次从堆顶取出最小的一个给它 ...
- CodeForces 549H | 二分答案
参考了这个博客哇 #include<cstdio> #include<algorithm> #include<cstring> #define Max(a,b,c, ...
- codeforces 466C 计数 codeforces 483B 二分 容斥
题意:给你n个数,将他们分成连续的三个部分使得每个部分的和相同,求出分法的种数. 思路:用一个数组a[i]记下从第一个点到当前i点的总和.最后一个点是总和为sum的点,只需求出总和为1/3sum的点和 ...
- Codeforces 700A As Fast As Possible(二分答案)
[题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
随机推荐
- ElasticSearch优化系列一:集群节点规划
节点职责单一,各司其职 elasticSearch的配置文件中有2个参数:node.master和node.data.这两个参 数搭配使用时,能够帮助提供服务器性能. 数据节点node.master: ...
- 杂项(乌班图、flex的使用实例)
查看乌班图当前系统版本:lsb_release -a 转载于博客园:flex的使用实例
- Delphi 调试连接 任意Android手机/平板/盒子
Delphi有时候无法连接调试一些手机,解决方案: 1.安装Google USB Driver 2.通过设备管理器查看手机或平板USB的VID,PID 3.修改你的电脑上的android_winusb ...
- linux用户及文件管理
帮助命令 whatis 命令 #显示命令的简短功能 man 命令 #查看手册页和命令描述 命令--help #适用于外部命令 help 命令 #适用于内部命令 type 命令 ...
- 基于STM32的简易数码相册
原理:在板子上插入SD卡,并使用FATFS文件系统来循环读取并显示SD卡内的指定目录内的所有BMP图片. 这是显示效果(能上传视频的话就能看到循环显示效果): 因为图片显示函数显示的是24位BMP图片 ...
- hadoop伪分布式组件安装
一.版本建议 Centos V7.5 Java V1.8 Hadoop V2.7.6 Hive V2.3.3 Mysql V5.7 Spark V2.3 Scala V2.12.6 Flume V1. ...
- android一个下拉放大库bug的解决过程及思考
android一个下拉放大库bug的解决过程及思考 起因 项目中要做一个下拉缩放图片的效果,搜索了下github上面,找到了两个方案. https://github.com/Frank-Zhu/Pul ...
- maven拓展——使用tomcat插件运行maven项目
首先,在pom.xml中配置插件: <build> <plugins> <plugin> <groupId>org.apache.tomcat.mave ...
- 20155231 实验三 敏捷开发与XP实践
20155231 实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑器&g ...
- 20155322 2017-2018-1《信息安全系统设计》第十周 课下作业-IPC
20155322 2017-2018-1<信息安全系统设计>课下作业-IPC 作业内容 研究Linux下IPC机制:原理,优缺点,每种机制至少给一个示例,提交研究博客的链接. 共享内存 管 ...