【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) = ...
随机推荐
- [RK3288][Android6.0] 调试笔记 --- 系统第一次开机进入Recovery模式原因【转】
本文转载自:http://blog.csdn.net/kris_fei/article/details/53464461 latform: ROCKCHIPOS: Android 6.0Kernel: ...
- Mybatis 碰到的一些问题
1. SQL语句参数无法获取:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no get ...
- B1800 [Ahoi2009]fly 飞行棋 数学模拟
20分钟一遍AC,大水题,我的算法比较复杂,但是好理解,就是找可以凑出来一半周长的点来暴力枚举就行了. 题干: Description 给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依 ...
- AAC帧格式及编码介绍
参考资料: AAC以adts格式封装的分析:http://wenku.baidu.com/view/45c755fd910ef12d2af9e74c.html aac编码介绍:http://wenku ...
- 棋盘问题(dfs)
http://poj.org/problem?id=1321 思路:按行搜索,回溯时还原棋盘. #include <stdio.h> #include <string.h> ] ...
- 0502 php-变量、常量
变 量 1.变量必须以$开头,后面紧跟变量名. 2.注意以下情况: echo “人民币符合¥像个羊,美元符号$象个钱”; //“$象个钱”会被识别为变量 3.与js的不同: 不支持“只 ...
- win7下安装memcache
Windows7 x64在Wamp集成环境下安装Memcache,步骤如下: 1.Memcached-win64 下载 (1)最新版本下载:http://blog.couchbase.com/memc ...
- linux随便贴贴
在bin目录下进入mysql: ./mysql -uroot -p123456 update mysql.user set password=password('root') where user=' ...
- Jmeter - 服务器性能检测
在对系统做压力测试时,往往需要对服务的性能进行监控,包括CPU,Memory,IO,还有网络情况进行监控. Jemter有个一插件,能很好的支持这些性能监控.原理是服务器启动服务之后,测试机发起请求, ...
- spring注解、aop(二)
使用注解配置spring 1.导入 spring-aop-5.0.6.RELEASE.jar包 2.为主配置文件引入新的命名空间 xmlns:context="http://www.spri ...