题目描述

Byteasar, the farmer, wants to plough his rectangular field. He can begin with ploughing a slice from any of the field's edges, then he can plough a slice from any unploughed field's edges, and so on, until the whole field is ploughed. After the ploughing of every successive slice, the yet-unploughed field has a rectangular shape. Each slice has a span of 111 , and the length and width of the field are the integers nnn and mmm .

Unfortunately, Byteasar has only one puny and frail nag (horse) at his disposal for the ploughing. Once the nag starts to plough a slice, it won't stop until the slice is completely ploughed. However, if the slice is to much for the nag to bear, it will die of exhaustion, so Byteasar has to be careful. After every ploughed slice, the nag can rest and gather strength. The difficulty of certain parts of the field varies, but Byteasar is a good farmer and knows his field well, hence he knows every part's ploughing-difficulty.

Let us divide the field into m×nm\times nm×n unitary squares - these are called tiles in short.

We identify them by their coordinates (i,j)(i,j)(i,j) , for 1≤i≤m1\le i\le m1≤i≤m and 1≤j≤n1\le j\le n1≤j≤n .

Each tile has its ploughing-difficulty - a non-negative integer.

Let ti,jt_{i,j}ti,j​ denote the difficulty of the tile which coordinates are (i,j)(i,j)(i,j) .

For every slice, the sum of ploughing-difficulties of the tiles forming it up cannot exceed a certain constant kkk - lest the nag dies.

A difficult task awaits Byteasar: before ploughing each subsequent slice he has to decide which edge of the field he'll plough, so that the nag won't die. On the other hand, he'd like to plough as few slices as possible.

TaskWrite a programme that:

reads the numbers kkk , mmm and nnn from the input file, as well as the ploughing-difficulty coefficients, determines the best way to plough Byteasar's field, writes the result to the output file.

Byteasar想耕种他那块矩形的田,他每次能耕种矩形的一边(上下左右都行),在他每次耕完后,剩下的田也一定是矩形,每块小区域边长为 111 ,耕地的长宽分别为 mmm 和 nnn ,不幸的是Byteasar只有一匹老弱的马,从马开始耕地开始,只有当它耕完了一边才会停下休息。但有些地会非常难耕以至于马会非常的累,因此Byteasar需要特别小心。当耕完了一边之后,马可以停下来休息恢复体力。每块地耕种的难度不一,但是Byteasar都非常清楚。我们将地分成 m×nm\times nm×n 块单位矩形——我们用坐标 (i,j)(i,j)(i,j) 来定义它们。每块地都有一个整数 ti,jt_{i,j}ti,j​ ,来定义 (i,j)(i,j)(i,j) 的耕种难度。所以每次马耕一边地时的难度就是所有它耕种的地的难度总和,对于这匹虚弱的马而言,这个值不能超过他的体力值。Byteasar想知道在马不死掉的情况下最少需要耕多少次才能把地耕完。

输入输出格式

输入格式:

There are three positive integers in the first line of the input file: kkk , mmm and nnn ,separated by single spaces, 1≤k≤200 000 0001\le k\le 200\ 000\ 0001≤k≤200 000 000 , 1≤m,n≤20001\le m,n\le 20001≤m,n≤2000 .

In the following nnn lines there are the ploughing-difficulty coefficients.

The line no. j+1j+1j+1 contains the coefficients t1,j,t2,j...,tn,mt_{1,j},t_{2,j}...,t_{n,m}t1,j​,t2,j​...,tn,m​ , separated by single spaces, 0≤ti,j≤100 0000\le t_{i,j}\le 100\ 0000≤ti,j​≤100 000 .

输出格式:

Your programme should write one integer to the output file: the minimum number of slices required to plough the field while satisfying the given conditions. Since we care for animals, we guarantee that the field can be ploughed according to the above rules. But remember, saving the nag is up to you!

输入输出样例

输入样例#1:

12 6 4
6 0 4 8 0 5
0 4 5 4 6 0
0 5 6 5 6 0
5 4 0 0 5 4

输出样例#1:

8

说明

感谢@NaVi_Awson 提供翻译

Solution:

  大鸡哥翻译题,贼有意思。

  本题一眼的不可做,连随机化都没有去打。

  正解非常神奇的贪心。

  首先可以确定的是答案的范围:$min(n,m)\leq ans\leq n+m$(显然的)。

  然后我们可以对纵列贪心,即尽可能的删两边的纵列,不行时再删最上和最下两行,至于上下两行被删的顺序,我们可以设定一个阀值$p,\; p\in[1,n]$,表示上层删的行数不超过$p$,当达到该阀值时就直接删最下行,这样确定出的优先级是先左右后上下。同理,将优先级改为先上下后左右,尽可能的删顶底的两行。在每次枚举时更新答案就好了。

  贪心的正确性证明:首先可以确定当横纵都能删时,按先左右后上下的优先级删去纵列后不会影响横行的删去(上次横纵都能删,现在删掉纵列,显然横行还是可以删去);而若纵列能删而横行不能删,那么删去纵列,横行能删的可能性会更高;而若横能删而纵不能删,则删去横行后,要删的纵列数并不会减少,所以后面还是尽可能的删去列,这样可以确定在纵列先与横行的优先级下,删行不会使得答案更优,保持该优先级能确保横行删的次数尽可能的少,所以答案最优为$m+k_1,\; k_1\in[1,n]$。但是可能某种情况下删行时最优(比如每行每列都能删,而行数小于列数),于是确定先上下后左右的优先级后,尽可能减少删列的次数,删行的最优解为$n+k_2,\; k_2\in[1,m]$。两者取最小值就是答案了。

代码:

#include<bits/stdc++.h>
#define il inline
#define ll long long
#define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(int (i)=(b);(i)>=(a);(i)--)
using namespace std;
const int N=2005;
int k,n,m,sl[N][N],sr[N][N],a[N][N],ans=0x7fffffff;il int gi(){int a=0;char x=getchar();while(x<'0'||x>'9')x=getchar();while(x>='0'&&x<='9')a=(a<<3)+(a<<1)+x-48,x=getchar();return a;
}il void solve(){int ln,rn,lm,rm,tot,sum;For(p,1,m){ln=1,rn=n,lm=1,rm=m,tot=0;while(ln<=rn&&lm<=rm){tot++;sum=sl[ln][rm]-sl[ln][lm-1];if(sum<=k){ln++;continue;}sum=sl[rn][rm]-sl[rn][lm-1];if(sum<=k){rn--;continue;}sum=sr[lm][rn]-sr[lm][ln-1];if(sum<=k&&lm<p){lm++;continue;}sum=sr[rm][rn]-sr[rm][ln-1];if(sum<=k){rm--;continue;}tot=0x7fffffff;break;}ans=min(ans,tot);}For(p,1,n){ln=1,rn=n,lm=1,rm=m,tot=0;while(ln<=rn&&lm<=rm){tot++;sum=sr[lm][rn]-sr[lm][ln-1];if(sum<=k){lm++;continue;}sum=sr[rm][rn]-sr[rm][ln-1];if(sum<=k){rm--;continue;}sum=sl[ln][rm]-sl[ln][lm-1];if(sum<=k&&ln<p){ln++;continue;}sum=sl[rn][rm]-sl[rn][lm-1];if(sum<=k){rn--;continue;}tot=0x7fffffff;break;}ans=min(ans,tot);}
}int main(){k=gi(),m=gi(),n=gi();For(i,1,n) For(j,1,m) a[i][j]=gi(),sl[i][j]=sl[i][j-1]+a[i][j];For(i,1,m) For(j,1,n) sr[i][j]=sr[i][j-1]+a[j][i];solve();cout<<ans;return 0;
}

转载于:https://www.cnblogs.com/five20/p/9314594.html

P3444 [POI2006]ORK-Ploughing相关推荐

  1. bzoj1513【POI2006】Tet-Tetris 3D

    1513: [POI2006]Tet-Tetris 3D Time Limit: 30 Sec  Memory Limit: 162 MB Submit: 733  Solved: 245 [Subm ...

  2. P3435 [POI2006]OKR-Periods of Words kmp + fail指针

    传送门 文章目录 题意: 思路: 题意: 思路: 转换一下题意,就是求一个最小公共前后缀,显然可以暴跳nenene数组,复杂度O(n2)O(n^2)O(n2),注意到我们每次都跳的话会跳到很多重复的位 ...

  3. P3437 [POI2006]TET-Tetris 3D

    题目 P3437 [POI2006]TET-Tetris 3D 做法 一眼就是二维线段树,仔细想想,赋值操作怎么办??\(lazy\)标记放在一维,下一次又来放个标记二维就冲突了 正解:永久化标记 怎 ...

  4. 【实战+源码】RGB-D移动抓取服务机器人(三)——3D目标识别定位(相机标定、ORK、linemod、find_object_2d/3d)

    因为冠肺疫情的原因,在家效率不高,但时间充沛,就针对3D目标的相关东西梳理一下. 完整代码github托管地址:https://github.com/pengxinyi-up/mobile-grab- ...

  5. 记录一下在ROS里调用ORK的苦逼历程

    ubuntu16系统下,ROS kinnect.是跟着这位大神的步骤走,但连连报错.ROS中的物体识别--ORK功能包的使用 1.运行  rosrun object_recognition_core ...

  6. 【bzoj1511】[POI2006]OKR-Periods of Words KMP-next数组

    原文地址:http://www.cnblogs.com/GXZlegend/p/6827027.html 题目描述 一个串是有限个小写字符的序列,特别的,一个空序列也可以是一个串. 一个串P是串A的前 ...

  7. [POI2006]OKR-Periods of Words

    ---恢复内容开始--- 题目描述 A string is a finite sequence of lower-case (non-capital) letters of the English a ...

  8. POI2006 ZAB-Frogs

    题目 一群青蛙正在摧毁Byteotia所有的庄稼. 一个叫Byteasar的农夫决定使用一种放在田里的奇特的"scarefrogs"来吓跑他们, 所有的青蛙在跳跃过程中都尽量使自己 ...

  9. 【题解】洛谷P3435 [POI2006] OKR-Periods of Words(KMP)

    洛谷P3435:https://www.luogu.org/problemnew/show/P3435 思路 来自Kamijoulndex大佬的解释 先把题面转成人话: 对于给定串的每个前缀i,求最长 ...

最新文章

  1. C++:搭建深度学习环境及实战
  2. 【转】温故之.NET 异步
  3. TurboMail手机客户端—强大的附件文档阅读能力
  4. Symmetric Tree (101)
  5. 4.2.2 - Logical and/or Operators
  6. adb服务无法开启问题解决方法
  7. react-native-router-flux 使用详解(三)
  8. 算法设计与分析:Jewels and Stones(Week 1)
  9. qcc512x_qcc302x开发调试笔记
  10. Linux快速查看OpenCV版本
  11. 鸿蒙系统如何添加桌面小程序,微信Windows版更新至3.0:批量管理联系人,小程序可添加至桌面...
  12. 重启计算机之前无法刷新,更新完补丁不断提示是否重启电脑的解决方法
  13. c语言里10h代表什么,bios 10h中断是什么意思啊?
  14. Bridging the Gap between Training and Inference for Neural Machine Translation翻译
  15. C语言利用数组输出26个小写字母
  16. 基于微信小程序的在线测试系统
  17. iptables 防火墙中的SNAT和DNAT
  18. 25_ue4实现二段跳,加速跑和瞬移
  19. vue中已声明XX,但从未读取其值 解决方法
  20. rancher 代理安装

热门文章

  1. 岂止于大 中国重汽VGV U75PLUS更是一台好玩的SUV
  2. totolinkn200up怎么设置_totolink300无线中继怎么设置
  3. ABP 详解系列2:解析ABP框架中的数据传输对象与应用服务
  4. 这些成功的人工智能应用,你见过哪几个?
  5. 虚拟偶像秦佑之担任推广大使,虚拟人制作技术带来文化艺术新体验
  6. 【网易测试】真题解析
  7. c语言编程格式错误是什么意思,求大神看看这个为什么在OJ上显示格式错误
  8. Java NIO SocketChannel读
  9. 在Ubunto上安装VMware Tools
  10. 从硬件到软件,低代码定制安灯(Andon)成为MES系统的全新增长点