B. Friends and Presents(Codeforces Round #275(div2)
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 andcnt2 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.
二分渣渣把二分又写跪了,总是分不清l与r的关系o(╯□╰)o,我居然l和r都推断了一下。这题居然l和r都能过。
这题就是枚举一下中间结果,对a周期为x-1,b周期为y-1,仅仅有当i为y的倍数时,仅仅能让a取,当i为x的倍数时,仅仅
能让b取,算一下x,y的倍数时两个都不能取得,a的总数量减去仅仅能a取的,b的总数量减去仅仅能b取的 ,剩下的要
取的和小于等于两个都能取得,这个值就是有效值。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long cnt1,cnt2,x,y;
long long gcd(long long a,long long b)
{
return b==0?a:gcd(b,a%b);
}
bool judge(long long v)
{
long long t1,t2,t3;
t1=v/x;
t2=v/y;
t3=v/(x*y/gcd(x,y));
long long temp1,temp2,temp3;
temp1=max((long long)0,cnt1-t2+t3);//t2-t3是仅仅能a取的,cnt1-仅仅能a取的,就是剩下a没取的
temp2=max((long long)0,cnt2-t1+t3);//t1-t3是仅仅能b取的,cnt2-仅仅能b取的,就是剩下b没取的
temp3=max((long long)0,v-t1-t2+t3);//x,y都能取的
if(temp3>=temp1+temp2)//a,b都能取的大于要大于等于a,b没取的和
return true;
else
return false;
}
int main()
{
scanf("%I64d%I64d%I64d%I64d",&cnt1,&cnt2,&x,&y);
long long l=1,r=2000000000;
long long u=0;
while(l<r)
{
int m=(l+r)>>1;
if(judge(m))
{
u=m;
r=m;
}
else
{
l=m+1;
}
}
// long long ans;
// if(judge(r))
// ans=r;
// else
// ans=l;
printf("%I64d\n",u);
return 0;
}
B. Friends and Presents(Codeforces Round #275(div2)的更多相关文章
- A. Counterexample (Codeforces Round #275(div2)
		
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...
 - C. Diverse Permutation(Codeforces Round #275(div2)
		
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...
 - Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
		
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
 - Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造
		
Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 ht ...
 - 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation
		
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
 - Codeforces Round #539 div2
		
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
 - 【前行】◇第3站◇ Codeforces Round #512 Div2
		
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
 - Codeforces Round#320 Div2 解题报告
		
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
 - Codeforces Round #564(div2)
		
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
 
随机推荐
- 微信开发_微信教程__微信通讯框架V1.0
			
做个广告先, PHP千人群(6848027) C++群 (1414577) 看雪汇编&反汇编群(15375777) 看雪汇编&反汇编2群(4915800) 转载不一定注明出处,只要推荐 ...
 - Git使用记录(二)
			
一)git init 初始化仓库 要使用Git进行版本管理,必须先初始化仓库,请先建立一个目录并初始化仓库 mkdir gittest cd gittest git init 初始化成功以后会在当前目 ...
 - [转]IOS Segment页面之间view的切换
			
有三个view,分别为view1.view2.view3,通过UISegmentedControl进行三个view的切换. @interface UIViewDemoViewController : ...
 - IOS 学习笔记(5) 控件 文本视图(UITextView)的使用方法
			
相对于UILabell所支持的较短文本内容,UITextView对于长文本的支持更好.UITextView能够以滚动的方式全部浏览到长文本,并且就像UILabel那样,从ISO6,他也提供了对NSAt ...
 - web附件中文名
			
response.setHeader("Content-Disposition", "attachement;filename="+URLEncoder.enc ...
 - BootStrap 轮播 Carousel
			
参考 http://wrongwaycn.github.io/bootstrap/docs/javascript.html#collapse 同样 启动方式有2种 一种是在div的class中加 另 ...
 - ubutun 下webalizer 分析Apache日志
			
http://www.webalizer.org/ 配置Webalizer 我们可以通过命令行配置Webalizer,也可以通过配置文件进行配置.下面将重点介绍使用配置文件进行配置,该方法使用形式比 ...
 - kinect for windows - DepthBasics-D2D详解之三
			
这篇文章我们将总结一下,之前两篇文章中提到的Kinect SDK的函数接. 函数接口: NuiGetSensorCount: 获取连接的Kinect设备个数 原型:_Check_return_ HRE ...
 - ACM—循环小数转变成分数知识点_C++实现
			
在小学的时候,我们的学生都能把“整数表示成分母是1的分数”,而且大多数学生也都能把有限小数和循环小数表示成分数的形式.这样,整数.分数.有限小数.循环小数都属于有理数.教科书中说“整数和分数统称有理数 ...
 - UBER司机奖励政策
			
高峰时段: 早高峰:早6:30-8:30点 晚高峰:晚4:00-7:00点 *周六日只有晚高峰 其他时间均为平峰时段 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注 ...