题目大意:
  有两种蛋糕,分别被切成了a块和b块,要把这些蛋糕分到n个盘子里。
  要求每个盘子里只能有一种蛋糕,每一种蛋糕都被分。问最优情况下,盘子里至少能放几个蛋糕。

思路:
  二分答案。
  由于每个蛋糕都要被分,所以二分的上界是min(a,b)而不是a+b。
  然后O(n)检验即可。

 #include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
inline bool check(const int &n,int a,int b,const int &m) {
for(register int i=;i<=n;i++) {
if(a>=m) {
a-=m;
continue;
}
if(b>=m) {
b-=m;
continue;
}
return false;
}
return true;
}
int main() {
const int n=getint(),a=getint(),b=getint();
int l=,r=std::min(a,b);
while(l<=r) {
const int mid=(l+r)>>;
if(check(n,a,b,mid)) {
l=mid+;
} else {
r=mid-;
}
}
printf("%d\n",l-);
return ;
}

[CF911B]Two Cakes的更多相关文章

  1. hdu 5997 rausen loves cakes(线段数合并+启发式修改)

    题目链接:hdu 5997 rausen loves cakes 题意: 给你n个点,每个点有一个颜色,现在有两个操作,第一个操作,将颜色x改为颜色y,第二个操作,询问[x,y]区间有多少颜色段(颜色 ...

  2. BZOJ3498PA2009 Cakes——三元环

    题目描述 N个点m条边,每个点有一个点权a.对于任意一个三元环(j,j,k)(i<j<k),它的贡献为max(ai,aj,ak) 求所有三元环的贡献和.N<100000,,m< ...

  3. Codeforces Round #542 B Two Cakes

    B. Two Cakes time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. [BZOJ 3498] [PA 2009] Cakes

    Description \(n\) 个点 \(m\) 条边,每个点有一个点权 \(a_i\). 对于任意一个三元环 \((i,j,k)(i<j<k)\),它的贡献为 \(\max(a_i, ...

  5. [Codeforces-911B] - Two Cakes

    B. Two Cakestime limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutpu ...

  6. Codeforces Round #413 A. Carrot Cakes

    A. Carrot Cakes time limit per test   1 second memory limit per test   256 megabytes   In some game ...

  7. Two Cakes

    It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has boug ...

  8. Educational Codeforces Round 35 B. Two Cakes【枚举/给盘子个数,两份蛋糕块数,最少需要在每个盘子放几块蛋糕保证所有蛋糕块都装下】

    B. Two Cakes time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. HDU 5997 rausen loves cakes(启发式合并 + 树状数组统计答案)

    题目链接  rausen loves cakes 题意  给出一个序列和若干次修改和查询.修改为把序列中所有颜色为$x$的修改为$y$, 查询为询问当前$[x, y]$对应的区间中有多少连续颜色段. ...

随机推荐

  1. C. Annoying Present SB题

    C. Annoying Present time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. javaScript获取文档中所有元素节点的个数

    HTML+JS 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  3. 转:Spring-session & redis 子域名共享session

    Spring-session & redis 子域名共享session 例子: a.example.com b.example.com spring 版本 4.2.6.RELEASE Spri ...

  4. codeforces 854 problem E

    E. Boredom Ilya is sitting in a waiting area of Metropolis airport and is bored of looking at time t ...

  5. bzoj1015: [JSOI2008]星球大战starwar 并查集+离线处理

    题目传送门 这道题可以改为离线处理 倒着找答案 这样删点就变成加点了 有了这个思想题目就很好写了哇 23333 #include<cstdio> #include<cstring&g ...

  6. KDJ回测

    # -*- coding: utf-8 -*- import os import pandas as pd # ========== 遍历数据文件夹中所有股票文件的文件名,得到股票代码列表stock_ ...

  7. KVM的qemu-kvm使用

    KVM: kvm,x86支持硬件辅助虚拟化技术(hvm) grep -E "(vmx|svm)" /proc/cpuinfo [root@dmsag ~]# ll /dev/kvm ...

  8. ros bashrc 无法source setup.sh

    不知道什么时候开始的,莫名其妙首先是QT闪退,无法找到头文件,然后命令行进去catkin无法提示catkin_make 手动source之后就好了 问题出现在bashrc中source失败了 所以检查 ...

  9. head first (二):观察者模式

    首先推荐一下别人写的,很不错可以参考,http://www.cnblogs.com/li-peng/archive/2013/02/04/2892116.html 1.定义 观察者模式:在对象之间定义 ...

  10. 对DDD中领域服务的理解

    CZ 能不能清晰具体区分service和实体的区别 网上有人用DCI来解决 不知道对不对 STST 我复习下DDD中的服务的概念了参与讨论啊CZ 这个我也看过 但是太过于笼统 STST STST 复习 ...