[Codeforces Round #275 (Div. 2)]B - Friends and Presents
最近一直在做 codeforces ,总觉得已经刷不动 BZOJ 了? ——真是弱喵
你看连 Div.2 的 B 题都要谢谢题解,不是闲就是傻
显然我没那么闲 ╮(╯_╰)╭
我觉得这题的想法挺妙的~
大意是你需要分别给 a 和 b cnt1 和 cnt2 个数字
但是 a 不要被 x 整除的数 ,as well as,b 不要被 y 整除的数
然后求需要给的最大数的最小值——
最值的最值?那不是典型的二分吗?
但是——坑爹的英文题导致我完全没有意识到这一点……
二分答案 v ,因为 a 不要被 x 整除的数,所以我们可以
先把 被 x 整除的数但不被 y 整除 给b,
再把 被 y 整除的数但不被 x 整除 给a。
然后剔除所有被 a*b 整除的数
剩下的数与 a 和 b 都互素,判一下能不能好好的分配就可以了
代码很好写哦
#include <cstdio>
#include <cstring> int cnt1, cnt2, x, y;
inline int getint();
inline void putint(long long);
inline bool check(long long); int main()
{
long long l, r, m; cnt1=getint(), cnt2=getint(), x=getint(), y=getint();
l=, r=0x0FFFFFFFFFFFFFFFLL;
while (l+<r)
{
m=(l+r)>>;
if (check(m)) r=m;
else l=m;
}
putint(r); return ;
}
inline int getint()
{
register int num=;
register char ch;
do ch=getchar(); while (ch<'' || ch>'');
do num=num*+ch-'', ch=getchar(); while (ch>='' && ch<='');
return num;
}
inline void putint(long long num)
{
char stack[];
register int top=;
for ( ;num;num/=) stack[++top]=num%+'';
for ( ;top;top--) putchar(stack[top]);
putchar('\n');
}
inline bool check(long long num)
{
long long u=num/x, v=num/y, w=num/(x*y);
long long c1=cnt1, c2=cnt2;
c1-=v-w; c2-=u-w;
if (c1<) c1=; if (c2<) c2=;
if (c1+c2>num-u-v+w) return false;
return true;
}
本傻英文 SB 系列
[Codeforces Round #275 (Div. 2)]B - Friends and Presents的更多相关文章
- Codeforces Round #275 (Div. 2) B. Friends and Presents 二分+数学
8493833 2014-10-31 08:41:26 njczy2010 B - Friends and Presents G ...
- 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 #275 (Div. 2) C
题目传送门:http://codeforces.com/contest/483/problem/C 题意分析:题目意思没啥好说的. 去搞排列列举必须TLE.那么就想到构造. 1.n.2.n-1.3.n ...
- Codeforces Round #275(Div. 2)-C. Diverse Permutation
http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...
- Codeforces Round #275 (Div. 2)-A. Counterexample
http://codeforces.com/contest/483/problem/A A. Counterexample time limit per test 1 second memory li ...
- Codeforces Round #275 Div.1 B Interesting Array --线段树
题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...
- Codeforces Round #275 (Div. 2)
A. Counterexample 题意:给出l,r,找出使得满足l<a<b<c<r,同时满足a,b的最大公约数为1,b,c的最大公约数为1,且a,b的最大公约数不为1 因为题 ...
随机推荐
- js之oop <四>对象管理
对象扩展管理 Object.isExtensible() 检测对象是否可扩展(一般返回true).Object.preventExtensions() 防止对象扩展. var p = {p1:&quo ...
- hdu2896病毒侵袭(ac自动机)
链接 ac自动机的模板题 说2个注意的地方 一是题目说明包含所有ASCII字符,可以开到0-127 包含空格 题目会输入多个源串,在加完当前的val值时,不应清0,可以开个标记数组. #include ...
- PHP 小方法之 写日志方法
if(! function_exists ('write_log') ) { function write_log($data, $name='debug', $date=null){ if (is_ ...
- OpenGL的API函数使用手册
(一)OpenGL函数库 格式: <库前缀><根命令><可选的参数个数><可选的参数类型> 库前缀有 gl.glu.aux.glut.wgl.glx.a ...
- cxf的soap风格+spirng4+maven 客户端
上篇博客介绍了,cxf的soap风格的服务端,现在我们写客户端来调用 1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...
- Linux运行级详解
对于那些在DOS/Win9x/NT平台下的高级用户而言,Linux似乎是一个怪物.没有config.sys,没有 autoexec.bat,具有个人特色的机器配置不知道从何开始. 需要说明的是,很多人 ...
- 解决:Unknown table engine 'InnoDB'
把查询mysql的结果输出到文件的过程中出现了错误 ERROR 1286 (42000): Unknown table engine 'InnoDB' 这个问题的原因是新版mysql是 ...
- CentOS7 安装RabbitMQ
第一.下载erlang和rabbitmq-server的rpm: http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos. ...
- java日期操作大全
摘自(http://www.blogjava.net/i369/articles/83483.html) java日期操作 大全 先来一个: 取得指定月份的第一天与取得指定月份的最后一天 http ...
- c#中对json数据的序列化和反序列化(笔记)
今天遇到在后台中要获取json格式数据里的某些值,网上查了些资料: string jsonstr = _vCustomerService.LoadCustomerbyNumTotalData(quer ...