[POI2006]ORK-Ploughing(贪心,枚举)
[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 11 , and the length and width of the field are the integers nn and mm .
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\times nm×n unitary squares - these are called tiles in short.
We identify them by their coordinates (i,j)(i,j) , for 1\le i\le m1≤i≤m and 1\le j\le n1≤j≤n .
Each tile has its ploughing-difficulty - a non-negative integer.
Let t_{i,j}ti,j denote the difficulty of the tile which coordinates are (i,j)(i,j) .
For every slice, the sum of ploughing-difficulties of the tiles forming it up cannot exceed a certain constant kk - 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 kk , mm and nn 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想耕种他那块矩形的田,他每次能耕种矩形的一边(上下左右都行),在他每次耕完后,剩下的田也一定是矩形,每块小区域边长为 11 ,耕地的长宽分别为 mm 和 nn ,不幸的是Byteasar只有一匹老弱的马,从马开始耕地开始,只有当它耕完了一边才会停下休息。但有些地会非常难耕以至于马会非常的累,因此Byteasar需要特别小心。当耕完了一边之后,马可以停下来休息恢复体力。每块地耕种的难度不一,但是Byteasar都非常清楚。我们将地分成 m\times nm×n 块单位矩形——我们用坐标 (i,j)(i,j) 来定义它们。每块地都有一个整数 t_{i,j}ti,j ,来定义 (i,j)(i,j) 的耕种难度。所以每次马耕一边地时的难度就是所有它耕种的地的难度总和,对于这匹虚弱的马而言,这个值不能超过他的体力值。Byteasar想知道在马不死掉的情况下最少需要耕多少次才能把地耕完。
输入输出格式
输入格式:
There are three positive integers in the first line of the input file: kk , mm and nn ,separated by single spaces, 1\le k\le 200\ 000\ 0001≤k≤200 000 000 , 1\le m,n\le 20001≤m,n≤2000 .
In the following nn lines there are the ploughing-difficulty coefficients.
The line no. j+1j+1 contains the coefficients t_{1,j},t_{2,j}...,t_{n,m}t1,j,t2,j...,tn,m , separated by single spaces, 0\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 提供翻译 同校队爷Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz Orz
考试的时候强行贪心:上下左右4条边找最大的可行边种,算边公式写错40,改对30?!
考虑如何贪心,最优的情况应该是全部竖着种或者全部横着种,对于竖着种,每多一次横着种都不会减少竖着种的次数,所以我们考虑尽量少的横着种。对于横着种也是同理。但是如果不能竖着种不符合条件的话,上和下怎么处理?我们可以直接枚举上最多种到哪里,取个min即可
#include<bits/stdc++.h>
using namespace std;
int read()
{
    int x=0,w=1;char ch=getchar();
    while(ch>'9'||ch<'0') {if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*w;
}
const int N=2010;
int n,m,v,num,sum,s,x,z,y,inf=2000000000,ans;
int a[N][N],sum1[N][N],sum2[N][N];
int d[3][2];
int shang(){return sum1[d[1][0]][d[2][1]]-sum1[d[1][0]][d[1][1]-1];}
int xia(){return sum1[d[2][0]][d[2][1]]-sum1[d[2][0]][d[1][1]-1];}
int zuo(){return sum2[d[2][0]][d[1][1]]-sum2[d[1][0]-1][d[1][1]];}
int you(){return sum2[d[2][0]][d[2][1]]-sum2[d[1][0]-1][d[2][1]];}
bool check()
{
    if(d[1][0]>d[2][0]) return false;
    if(d[1][1]>d[2][1]) return false;
    return true;
}
int work1(int i)
{
    int qwe=0;d[1][0]=d[1][1]=1;d[2][0]=n;d[2][1]=m;
    while(check())
    {
        qwe++;
        s=shang();x=xia();z=zuo();y=you();
        if(z<=v) d[1][1]++;
        else if(y<=v) d[2][1]--;
        else if(s<=v&&d[1][0]<i) d[1][0]++;
        else if(x<=v) d[2][0]--;
        else {qwe=inf;break;}
    }
    return qwe;
}
int work2(int i)
{
    int qwe=0;d[1][0]=d[1][1]=1;d[2][0]=n;d[2][1]=m;
    while(check())
    {
        qwe++;
        s=shang();x=xia();z=zuo();y=you();
        if(s<=v) d[1][0]++;
        else if(x<=v) d[2][0]--;
        else if(z<=v&&d[1][1]<i) d[1][1]++;
        else if(y<=v) d[2][1]--;
        else {qwe=inf;break;}
    }
    return qwe;
}
int main()
{
    //freopen("ork.in","r",stdin);
    //freopen("ork.out","w",stdout);
    v=read();m=read();n=read();ans=inf;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    a[i][j]=read(),sum1[i][j]=sum1[i][j-1]+a[i][j],sum2[i][j]=sum2[i-1][j]+a[i][j];
    for(int i=1;i<=n;i++) ans=min(ans,work1(i));
    for(int i=1;i<=m;i++) ans=min(ans,work2(i));
    cout<<ans;
    return 0;
}
												
											[POI2006]ORK-Ploughing(贪心,枚举)的更多相关文章
- POJ 1018 Communication System 贪心+枚举
		
看题传送门:http://poj.org/problem?id=1018 题目大意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m个厂家提供生产,而每个厂家生产的同种设备都 ...
 - 【搜索】POJ-2718 贪心+枚举
		
一.题目 Description Given a number of distinct decimal digits, you can form one integer by choosing a n ...
 - [APIO2015]巴厘岛的雕塑 --- 贪心 + 枚举
		
[APIO2015]巴厘岛的雕塑 题目描述 印尼巴厘岛的公路上有许多的雕塑,我们来关注它的一条主干道. 在这条主干道上一共有\(N\)座雕塑,为方便起见,我们把这些雕塑从 1 到\(N\)连续地进行 ...
 - 51nod1475(贪心&枚举)
		
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1475 题意:中文题诶- 思路:看懂题意后,首先想到的是贪心: ...
 - hdu 4091 Zombie’s Treasure Chest 贪心+枚举
		
转自:http://blog.csdn.net/a601025382s/article/details/12308193 题意: 输入背包体积n,绿宝石体积s1,价值v1,蓝宝石体积s2,价值v2,宝 ...
 - HDU 5303 Delicious Apples (贪心 枚举 好题)
		
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
 - 贪心+枚举/哈希表 HDOJ Trouble
		
题目传送门 题意:5个集合,每个集合最多200个数字,问是否每个集合挑一个数加起来和为0. 分析:显然n^5的程序果断超时,甚至n^3logn的二分也过不了.想n^3的方法,既然判断有没有,那么可以将 ...
 - Delicious Apples  (hdu 5303 贪心+枚举)
		
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
 - HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)
		
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
 
随机推荐
- [BZOJ3236][AHOI2013]作业:树套树/莫队+分块
			
分析 第一问随便搞,直接说第二问. 令原数列为\(seq\),\(pre_i\)为\(seq_i\)这个值上一个出现的位置,于是可以简化询问条件为: \(l \leq i \leq r\) \(a \ ...
 - Java继承和多态-Static关键字
			
1. 什么是Static 关键字? Static 能够与变量,方法和类一起使用,称为静态变量,静态方法.如果在一个类中使用static修饰变量或者方法的话,它们可以直接通过类访问,不需要创建一个类的对 ...
 - React-Native 之 GD (十六)首页筛选功能
			
1.首页筛选功能 GDCommunalSiftMenu.js /** * 筛选菜单 */ import React, { Component, PropTypes } from 'react'; im ...
 - (一)Maven之使用入门
			
目录 今天是端午节哦,昨天大学同学举个了会.鱼头泡饼贼拉香,嗯哼,有点跑题了:之后去了同学家里坐了坐:发现同我有一样的书,即:<maven实战>:记得是从二手网店淘到的,已经买了有小半年, ...
 - 阶段1 语言基础+高级_1-2 -面向对象和封装_16this关键字的作用
			
this主要是在重名的情况下 ,起到区分的效果 新建demo04的包,里面新建类Person 通过this.进行区分 this关键字可以解决重名 分不开的问题 这里的person调用的sayHello ...
 - 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_02 递归_4_练习_递归打印多级目录
			
递归所有的文件夹,并把文件都输出出来. 在最上面打印目录的名称
 - axios 获取不到数据错误
			
1.问题: 打算学习下vue,但是vue-resource作者已经不更新了,并且大家都建议用axios来进行前后端交互,所以就从学习axios开始. 但是在使用 axios 的过程中,自己写的接口竟然 ...
 - C++ 全面刨析使用指针方法 _new _delete
			
指针 #include<iostream> using namespace std; int main() { ; int* pn;//声明 int* pn = &avr;//初始 ...
 - 关于mysql的使用命令(持续更新中...)
			
特别提示 本说明中的mysql 是基于windwos平台下的5.5 版本 安装完成后 请到mysql中设置配置文件 链接分享:链接:https://pan.baidu.com/s/1tv4ulZ ...
 - MySQL-第十五篇使用连接池管理连接
			
1.数据库连接池的解决方案是: 当应用程序启动时,系统主动建立足够的数据库连接,并将这些连接组成一个连接池.每次应用程序请求数据库连接时,无需重新打开连接,而是从连接池中取出已有的连接使用,使用完后不 ...