描述

Bessie has baked a rectangular brownie that can be thought of as an RxC grid (1 <= R <= 500; 1 <= C <= 500) of little brownie squares.
The square at row i, column j contains N_ij (0 <= N_ij <= 4,000) chocolate chips.
Bessie wants to partition the brownie up into A*B chunks (1 <= A <= R; 1 <= B <= C): one for each of the A*B cows. The brownie is cut by first making A-1 horizontal cuts (always along integer
coordinates) to divide the brownie into A strips.  Then cut each strip *independently* with B-1 vertical cuts, also on integer boundaries. The other A*B-1 cows then each choose a brownie piece, leaving the last chunk for Bessie. Being greedy, they leave Bessie the brownie that has the least number of chocolate chips on it.
Determine the maximum number of chocolate chips Bessie can receive, assuming she cuts the brownies optimally.
As an example, consider a 5 row x 4 column brownie with chips distributed like this:
         1 2 2 1
         3 1 1 1
         2 0 1 3
         1 1 1 1
         1 1 1 1
Bessie must partition the brownie into 4 horizontal strips, each with two pieces. Bessie can cut the brownie like this:

1 2 | 2 1
       ---------
       3 | 1 1 1
       ---------
       2 0 1 | 3
       ---------
       1 1 | 1 1
       1 1 | 1 1

Thus, when the other greedy cows take their brownie piece, Bessie still gets 3 chocolate chips.

输入

* Line 1: Four space-separated integers: R, C, A, and B

* Lines 2..R+1: Line i+1 contains C space-separated integers: N_i1, ..., N_iC

输出

* Line 1: A single integer: the maximum number of chocolate chips that Bessie guarantee on her brownie

样例输入

5 4 4 2
1 2 2 1
3 1 1 1
2 0 1 3
1 1 1 1
1 1 1 1

样例输出

3

题目大意:

给一个R*C的矩阵,先横着切A-1刀,分成A份,然后每份切B-1刀,最终有A*B份,求里面的最小值的最大值。

二分枚举答案,然后判断是否可行。

#include <bits/stdc++.h>
using namespace std;
int r,c,a,b;
int s[][],pre[][];
bool check(int x)
{
int cnt=,la=;
for(int i=;i<=r;i++)
{
int sum=,num=;
for(int j=;j<=c;j++)
{
if(sum+pre[i][j]-pre[i][j-]-pre[la][j]+pre[la][j-]<x)
sum+=pre[i][j]-pre[i][j-]-pre[la][j]+pre[la][j-];
else
sum=,num++;
}
if(num>=b)///说明这部分能被切除b份,且符合要求
la=i,cnt++;///更新上一次切的行的位置
}
return cnt>=a;
}
int main()
{ scanf("%d%d%d%d",&r,&c,&a,&b);
for(int i=;i<=r;i++)
for(int j=;j<=c;j++)
scanf("%d",&s[i][j]);
for(int i=;i<=r;i++)///处理前缀和
for(int j=;j<=c;j++)
pre[i][j]=pre[i-][j]+pre[i][j-]-pre[i-][j-]+s[i][j];
int L=,R=pre[r][c],ans;
while(L<=R)
{
//cout<<L<<' '<<R<<'\n';
int mid=(L+R)>>;
if(check(mid))
L=mid+,ans=mid;
else R=mid-;
}
printf("%d\n",ans);
return ;
}

Brownie Slicing(二分枚举答案)的更多相关文章

  1. BZOJ 2196: [Usaco2011 Mar]Brownie Slicing( 二分答案 )

    二分答案就可以了.... ----------------------------------------------------------------------- #include<cst ...

  2. POJ 2112—— Optimal Milking——————【多重匹配、二分枚举答案、floyd预处理】

    Optimal Milking Time Limit:2000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Sub ...

  3. POJ3228 并查集或二分最大流枚举答案

    忘记写题意了.这题题意:给出每个地点的金矿与金库的数量,再给出边的长度.求取最大可通过边长的最小权值使每个金矿都能运输到金库里. 这题和之前做的两道二分枚举最大流答案的问法很相识,但是这里用最大流速度 ...

  4. BZOJ_2196_[Usaco2011 Mar]Brownie Slicing_二分答案+贪心

    BZOJ_2196_[Usaco2011 Mar]Brownie Slicing_二分答案+贪心 Description Bessie烘焙了一块巧克力蛋糕.这块蛋糕是由R*C(1 <= R,C ...

  5. NC24622 Brownie Slicing

    NC24622 Brownie Slicing 题目 题目描述 Bessie has baked a rectangular brownie that can be thought of as an ...

  6. 两条直线(蓝桥杯)二分枚举+RMQ

    算法提高 两条直线   时间限制:1.0s   内存限制:256.0MB        问题描述 给定平面上n个点. 求两条直线,这两条直线互相垂直,而且它们与x轴的夹角为45度,并且n个点中离这两条 ...

  7. 无题II hdu 2236(二分枚举区间)

    分析:只需要用二分找一个区间,然后不断枚举这个区间是否可以达到最大匹配,一直二分到答案为止.   代码: =============================================== ...

  8. POJ 3189——Steady Cow Assignment——————【多重匹配、二分枚举区间长度】

     Steady Cow Assignment Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  9. Codeforces J. Sagheer and Nubian Market(二分枚举)

    题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes in ...

随机推荐

  1. JVM垃圾回收机制二

    对象的回收 垃圾的回收涉及的几个问题:何时回收,由谁回收,怎样回收.这几个问题我们一一来解决. 1.何时回收----对象的生死判定 对象达到什么条件才能判断这个对象已经无用了.常见的判断对象生死的方法 ...

  2. substring和substr,slice和splice

    substring 和 substr 这二货都是针对字符串而言的,且都是返回一个副本,而不是在原字符串上直接操作. 上代码: var str = '0123456789'; console.log( ...

  3. div+css 布局经验 - 最简单的 = 最不变形的(原创技巧)

    站酷几年了 一直饱受其恩泽 尤为感激 一直想奉献些什么 但是苦于水平 苦于奔波 今天静下心来 为大家奉献下 自己的div+css 经验 ,以下观点只代表 深海个人立场 希望为初学者提供一条" ...

  4. Azure 项目构建 – 部署 Drupal 网站

    通过完整流程详细介绍了如何通过 Azure Web 应用. MySQL DB on Azure 等服务在 Azure 平台上快速搭建 Drupal 服务器,并将其连接到 MySQL 数据库. 此系列的 ...

  5. MySQL字符集和排序介绍

    客服端字符集: character_set_client utf8mb4连接字符集: character_set_connection utf8mb4数据库字符集: character_set_dat ...

  6. python hdfs初体验

    新建目录 chr 新建文件hdfstest1.txt并写入内容 复制hdfstest1.txt的内容到hdfstest2.txt

  7. OpenCascade: 获取边的端点

    FirstV = TopExp::FirstVertex(aEdge1); LastV = TopExp::LastVertex(aEdge1);

  8. 第1节 flume:11、flume的failover机制实现高可用

    1.4 高可用Flum-NG配置案例failover 在完成单点的Flume NG搭建后,下面我们搭建一个高可用的Flume NG集群,架构图如下所示: 图中,我们可以看出,Flume的存储可以支持多 ...

  9. Spring对注解(Annotation)处理【转】

    1.从Spring2.0以后的版本中,spring也引入了基于注解(Annotation)方式的配置,注解(Annotation)是JDK1.5中引入的一个新特性,用于简化Bean的配置,某些场合可以 ...

  10. iOS开发各种证书问题

    引言 写在前面 一.App ID(bundle identifier)     二.设备(Device)     三.开发证书(Certificates) 四.供应配置文件(Provisioning ...