[USACO15JAN]牛的矩形Cow Rectangles

本文介绍了USACO竞赛中的一道题目——'牛的矩形Cow Rectangles',主要涉及极大子矩形的求解方法,通过单调栈配合二分查找来解决空白部分,从而实现矩形的有效压缩。详细题解和代码解决方案提供。
摘要由CSDN通过智能技术生成

[USACO15JAN]牛的矩形Cow Rectangles

极大子矩形·单调栈·二分

题解:

先单调栈求极大子矩形,对于每个再二分压缩掉空白的部分。

Code:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define D(x) cout<<#x<<" = "<<x<<"  "
#define E cout<<endl
using std::vector;
using std::min;
using std::max;
using std::cout;
using std::endl;
const int N = 7;
const int INF = 0x3f3f3f3f;

struct Rect{
    int x1,y1,x2,y2;
    Rect(){}
    Rect(int _x1,int _y1,int _x2,int _y2){ x1=_x1; y1=_y1; x2=_x2; y2=_y2; }
    int getSquare(){ return (x2-x1)*(y2-y1); }
    void print(){ D(x1); D(y1); D(x2); D(y2); D(getSquare()); E; }
};

int m; int g[N+5][N+5],sum[N+5][N+5];
int height[N+5][N+5],left[N+5][N+5],right[N+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值