传送门

文章目录

  • 题意:
  • 思路:

题意:

有两种物品分别有x,yx,yx,y个,每次可以从一个拿出aaa个,另一个拿出bbb个分成一组,问最多能分成多少组。

思路:

这个题有一个显然的单调性,所以二分一个midmidmid表示拿了midmidmid个组,考虑如何checkcheckcheck。
设kkk为从第一个物品中拿了kkk次aaa个,那么可以列出如下两个不等式:x≤k∗a+(mid−k)∗bx\le k*a+(mid-k)*bx≤k∗a+(mid−k)∗by≤(mid−k)∗a+k∗by\le (mid-k)*a+k*by≤(mid−k)∗a+k∗b
将变量kkk单独拿出来:
k≥y−mid∗ab−ak\ge \frac{y-mid*a}{b-a}k≥b−ay−mid∗a​
k≤x−mid∗ba−bk\le \frac{x-mid*b}{a-b}k≤a−bx−mid∗b​
当然kkk还有一个自然范围[0,mid][0,mid][0,mid],所以问题转换成了是否存在这样的left≤k≤rightleft \le k \le rightleft≤k≤right,由于是浮点数,左边上取整,右边下取整即可。

// Problem: G. Gift Set
// Contest: Codeforces - Codeforces Round #725 (Div. 3)
// URL: https://codeforces.com/contest/1538/problem/G
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int a,b,x,y;bool check(LL mid) {LL left=ceil(1.0l*(y-a*mid)/(b-a));LL right=floor(1.0l*(x-b*mid)/(a-b));if(left<=mid&&right>=0&&left<=right) return true;return false;
}int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);int _; scanf("%d",&_);while(_--) {scanf("%d%d%d%d",&x,&y,&a,&b);if(a==b) {printf("%d\n",min(x,y)/a);continue;}if(a<b) swap(a,b);int l=0,r=1e9,ans=-1;while(l<=r) {int mid=l+r>>1;if(check(mid)) ans=mid,l=mid+1;else r=mid-1;}printf("%d\n",ans);}return 0;
}
/**/

Codeforces Round #725 (Div. 3) G. Gift Set 二分相关推荐

  1. Codeforces Round #644 (Div. 3) G.A/B Matrix

    Codeforces Round #644 (Div. 3) G.A/B Matrix 题目链接 You are given four positive integers n, m, a, b (1≤ ...

  2. Codeforces Round #731 (Div. 3) G. How Many Paths? dfs + 拓扑 + 思维

    传送门 题意: 给你一张nnn个点mmm条边的图,让你对每个点确定一个编号,规则如下: (1)(1)(1) 对于不能到的点编号为000. (2)(2)(2) 对于只有一条路径能到这个点的点编号为111 ...

  3. Codeforces Round #592 (Div. 2) G. Running in Pairs 构造(水)

    传送门 文章目录 题意: 思路: 题意: 思路: 史上最水GGG题,没有之一. 考虑最小的情况如何构造,显然就是让a,ba,ba,b都1−n1-n1−n依次排列即可,这样的最小值为n∗(n+1)2\f ...

  4. Codeforces Round #725 (Div. 3) 题解

    文章目录 A. Stone Game B. Friends and Candies C. Number of Pairs D. Another Problem About Dividing Numbe ...

  5. Codeforces Round #827 (Div. 4) G. Orray

    Problem - G - Codeforces 题意: 给定一个数列,让你重新排列这个数列,使得其前缀或最大 思路: 贪心策略就是找一个与pre或起来最大的值 重点是怎么写呢 感觉div4的题思路都 ...

  6. Codeforces Round #827 (Div. 4) G. Orray 解题报告

    原题链接: Problem - G - Codeforces 题目描述: You are given an array aa consisting of nn nonnegative integers ...

  7. Codeforces Round #693 (Div. 3)G. Moving to the Capital

    题目链接:Problem - G - Codeforces 题目大意:给定一张n个节点m条边的图,定义d数组为每个结点到结点1的距离. 每次可以选择两个操作:1,跳到结点x,dx>d当前 2.跳 ...

  8. Codeforces Round #693 (Div. 3) G. Moving to the Capital dp + 思维

    传送门 题意: 给一个图,111号点为中心点,定义dis[i]dis[i]dis[i]表示111号点到iii的距离.现在有三种移动方式 (1)(1)(1)从iii移动到jjj且dis[i]<di ...

  9. Codeforces Round #786 (Div. 3) G. Remove Directed Edges——树形dp+记忆化

    思路参考 题目链接 思路 题目要求删除一些边,要让最后每个点的入度,出度都小于最开始的情况,或者等于0. 那么出度为1或者入度为1的边一定会被删掉,而且题目说明不存在重边和环,最后的结果一定是一条链. ...

最新文章

  1. 深蓝学院的深度学习理论与实践课程:第三章
  2. 定义一个栈(Stack)类,用于模拟一种具有后进先出(LIFO)特性的数据结构
  3. 2.7.3 ecshop php7.1_ECshop 迁移到 PHP7版本时遇到的兼容性问题
  4. 基线检查工具_最新版CAD燕秀工具箱2.87(支持20042021)
  5. 盈利模型的内容都有哪些?
  6. JAVA math.sin(X)画圆_关于Math.sin(),Math.cos()画圆
  7. postgresql  null 值 不受查询条件约束
  8. LINUX SHELL使用变量控制循环
  9. 【黑苹果教程】Airport-miniPCIe 无线网卡驱动
  10. 关于DNF的多媒体包NPK文件的那些事儿(10) - SPK文件
  11. 浏览器 Cookie 的使用
  12. R语言之K-mean聚类分析
  13. Windows打开文件后提示,文件或目录损坏无法读取。
  14. HDU多校第六场——HDU6638 Snowy Smile(线段树区间合并)
  15. oracle 创建会话表,oracle临时会话表在存储过程中的使用
  16. 中国书信礼仪 (三)
  17. 【mmdetection3d】——3D 目标检测 NuScenes 数据集
  18. DIVA系列前期环境
  19. PMP备考之路 - 敏捷实践第五讲(实施敏捷:在敏捷环境中交付)
  20. 激荡10年,珍贵的毕业礼物

热门文章

  1. linux 编译指cpu内核,linux内核编译与配置
  2. python生成静态库_使用boost.python静态库
  3. 日本第一赘婿!他入赘近20年拿下诺贝尔奖,成名后不忘教光棍讨老婆......
  4. 50种奇妙装置玩法,将STEM教育一网打尽
  5. 2018年大数据趋势
  6. c 中oracle连接字符串,Oracle连接字符串C#
  7. php 分享微博,php微信分享到朋友圈、QQ、朋友、微博
  8. 教之初计算机考试函数应用题,教之初计算机考试系统
  9. python面向对象继承_四. python面向对象(继承)
  10. 输出螺旋数字正方形java_Java实现顺时针输出螺旋二维数组的方法示例