P3444 [POI2006]ORK-Ploughing
题目描述
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!
输入输出样例
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
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=;
int k,n,m,sl[N][N],sr[N][N],a[N][N],ans=0x7fffffff; il int gi(){
int a=;char x=getchar();
while(x<''||x>'')x=getchar();
while(x>=''&&x<='')a=(a<<)+(a<<)+x-,x=getchar();
return a;
} il void solve(){
int ln,rn,lm,rm,tot,sum;
For(p,,m){
ln=,rn=n,lm=,rm=m,tot=;
while(ln<=rn&&lm<=rm){
tot++;
sum=sl[ln][rm]-sl[ln][lm-];
if(sum<=k){ln++;continue;}
sum=sl[rn][rm]-sl[rn][lm-];
if(sum<=k){rn--;continue;}
sum=sr[lm][rn]-sr[lm][ln-];
if(sum<=k&&lm<p){lm++;continue;}
sum=sr[rm][rn]-sr[rm][ln-];
if(sum<=k){rm--;continue;}
tot=0x7fffffff;break;
}
ans=min(ans,tot);
}
For(p,,n){
ln=,rn=n,lm=,rm=m,tot=;
while(ln<=rn&&lm<=rm){
tot++;
sum=sr[lm][rn]-sr[lm][ln-];
if(sum<=k){lm++;continue;}
sum=sr[rm][rn]-sr[rm][ln-];
if(sum<=k){rm--;continue;}
sum=sl[ln][rm]-sl[ln][lm-];
if(sum<=k&&ln<p){ln++;continue;}
sum=sl[rn][rm]-sl[rn][lm-];
if(sum<=k){rn--;continue;}
tot=0x7fffffff;break;
}
ans=min(ans,tot);
}
} int main(){
k=gi(),m=gi(),n=gi();
For(i,,n) For(j,,m) a[i][j]=gi(),sl[i][j]=sl[i][j-]+a[i][j];
For(i,,m) For(j,,n) sr[i][j]=sr[i][j-]+a[j][i];
solve();
cout<<ans;
return ;
}
P3444 [POI2006]ORK-Ploughing的更多相关文章
- [洛谷P3444] [POI2006]ORK-Ploughing
洛谷题目链接[POI2006]ORK-Ploughing 题目描述 Byteasar, the farmer, wants to plough his rectangular field. He ca ...
- 洛谷P3444 [POI2006]ORK-Ploughing [枚举,贪心]
题目传送门 ork 格式难调,题面就不放了. 分析: 一道偏难的贪心和枚举题.考试的时候是弃疗了...yyb巨佬已经讲的很详细了,推荐他的博客.这里小蒟蒻就只放代码了. Code: #include& ...
- [POI2006]ORK-Ploughing(贪心,枚举)
[POI2006]ORK-Ploughing 题目描述 Byteasar, the farmer, wants to plough his rectangular field. He can begi ...
- 【BZOJ】【1520】【POI2006】Szk-Schools
网络流/费用流 比较裸的一道题 依旧是二分图模型,由源点S连向每个学校 i (1,0),「注意是连向第 i 所学校,不是连向学校的标号m[i]……唉这里WA了一次」 然后对于每所学校 i 连接 j+n ...
- BZOJ1510: [POI2006]Kra-The Disks
1510: [POI2006]Kra-The Disks Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 265 Solved: 157[Submit][ ...
- bzoj 1513 [POI2006]Tet-Tetris 3D(二维线段树)
1513: [POI2006]Tet-Tetris 3D Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 540 Solved: 175[Submit ...
- BZOJ1524: [POI2006]Pal
1524: [POI2006]Pal Time Limit: 5 Sec Memory Limit: 357 MBSubmit: 308 Solved: 101[Submit][Status] D ...
- BZOJ1511: [POI2006]OKR-Periods of Words
1511: [POI2006]OKR-Periods of Words Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 174 Solved: 92[Su ...
- Poi2006 Palindromes
2780: Poi2006 Palindromes Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 15 Solved: 5[Submit][Stat ...
随机推荐
- mysql的数据操作和内置功能总结
一.数据的增删改查 1.插入数据 a.插入完整数据(顺序插入) INSERT INTO 表名(字段1,字段2,字段3…字段n) VALUES(值1,值2,值3…值n); INSERT INTO 表名 ...
- ECSHOP和SHOPEX快递单号查询德邦插件V8.6专版
发布ECSHOP说明: ECSHOP快递物流单号查询插件特色 本ECSHOP快递物流单号跟踪插件提供国内外近2000家快递物流订单单号查询服务例如申通快递.顺丰快递.圆通快递.EMS快递.汇通快递.宅 ...
- libpng的使用
zlib 适用于数据压缩的函式库,由Jean-loup Gailly (负责compression)和 Mark Adler (负责decompression)开发. zlib被设计成一个免费的.通用 ...
- OMAPL138制作SD卡启动介质及重装Linux系统
OMAPL138制作SD卡启动盘及重装Linux系统 手里的创龙的OMAPL138平台的系统SSH坏掉了,我重新移植了openssh还是不好使,没有办法了只能重装OMAPL138的系统了,按照创龙给的 ...
- python学习——基本数据类型
一.运算符 1.算术运算: 2.比较运算 3.赋值运算 4.逻辑运算 5.成员运算 二.基本数据类型 1.数字 1.1 整形数字和长整形数字:在32位机器上,整数的位数为32位,取值范围为-2**31 ...
- 转译符,re模块,random模块
一, 转译符 1.python 中的转译符 正则表达式中的内容在Python中就是字符串 ' \n ' : \ 转移符赋予了这个n一个特殊意义,表示一个换行符 ' \ \ n' : \ \ 表示取 ...
- echarts实用小技巧,控制字符串长度,限定整数等
限定横坐标文本字符长度 xAxis : [ axisLabel:{ formatter: function (value) { var maxlength=6; if (value.length> ...
- GIT LFS 使用笔记
一.背景 由于git上传文件大小受限,所以我们需要使用GIT LFS对大小超过一定上限的大文件进行处理. 二.安装 linux上安装参见 https://askubuntu.com/questions ...
- hdu畅通工程(并查集)
Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道 ...
- 【python3.X】Scrapy学习途径参考
如何爬取属性在不同页面的itemhttp://scrapy-chs.readthedocs.io/zh_CN/0.24/topics/request-response.html#topics-requ ...