描述

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. 解决Git在更新项目时报凭证错误(Authentication failed)

    报此错误,大概率原因是用户名和密码弄错了,我用的阿里云,在网上找了半天发现Git远程仓库用的用户名和密码不是阿里云登陆用的账户密码,必须另外设置: 链接:code.aliyun.com/profile ...

  2. 集成SpringMVC, Spring, Mybatis环境

    web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version=" ...

  3. Android Studio 遇到的java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessExce问题

    在将一个Eclipse的项目转移到AndroidStudio的过程中,碰到了的问题如下: Error:Execution failed for task ':learnChinese:mergeDeb ...

  4. Windows系统下Android开发环境搭建

    “工具善其事,必先利其器”.要想学好Android,搭建好Android开发环境是一个良好的开端. Windows系统下Android开发环境主要有4个大的步骤.分别是: 1.JDK的安装 2.ecl ...

  5. springMVC 中 ajax get 请求和 post 请求的坑以及参数传递

    1, ajax 请求 无论为 post ,或者 get ,url中带有?形式的参数,后台都能以String类型变量接收,变量名称和参数名称必须一致 前台ajax: $.ajax( "prod ...

  6. Android学习总结(十四) ———— ListView Item多布局的实现

    一.基本概念 实现一个Item的多布局.像我们经常在用的各种即时通讯工具,QQ.微信等,假设他们的会话界面是ListView实现的,那么ListView就有多种Item布局,要实现ListView里面 ...

  7. 转载自infoq:MYSQL的集群方案

    分布式MySQL集群方案的探索与思考 2016-04-29 张成远  “本文整理自ArchSummit微信大讲堂张成远线上群分享内容   背景   数据库作为一个非常基础的系统,任何一家互联网公司都会 ...

  8. mysql 存在更新,不存在插入

    String sql = "insert into wb_result " + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ...

  9. KissXML的XPath选取问题

    XMPPFramework用的XML解析库还是大神自己写的KissXML,有些人生下来就是让人仰望的,哎. 进入主题,如下一段XML: <paramsxmlns="namespace& ...

  10. syslog(),closelog()与openlog()--日志操作函数 (1)

    文章出处:http://blog.csdn.net/xx77009833/archive/2010/07/30/5776383.aspx 为了满足某些目的,进行日志记录是很有必要的. 在典型的 LIN ...