挺好的一道题呢

O(n^2)或者O(wh)

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream> using namespace std; void setIO(const string& s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
} template<typename Q> Q read(Q& x) {
static char c, f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
return f && (x = -x), x;
}
template<typename Q> Q read() {
static Q x; return read(x);
} const int N = + ; struct Node {
int x, y;
Node(int x = , int y = ) : x(x), y(y) {}
}p[N]; bool cmpx(const Node& lhs, const Node& rhs) {
return lhs.x < rhs.x;
} bool cmpy(const Node& lhs, const Node& rhs) {
return lhs.y < rhs.y;
} int L, H, n;
int calc() {
int ans = ;
for(int i = ; i < n; i++) {
int U = H, D = ;
for(int j = i + ; j < n; j++) {
ans = max(ans, (p[j].x - p[i].x) * (U - D));
if(D <= p[j].y && p[j].y <= U) {
if(p[j].y > p[i].y) U = p[j].y;
else D = p[j].y;
}
if(U == D) break;
}
}
return ans;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif read(H), read(L), read(n);
for(int i = ; i < n; i++) {
int x = read<int>(), y = read<int>();
p[i] = Node(x, y);
}
p[n++] = Node(, );
p[n++] = Node(, H);
p[n++] = Node(L, );
p[n++] = Node(L, H); int ans = ;
sort(p, p + n, cmpy);
for(int i = ; i < n; i++) {
ans = max(ans, (p[i].y - p[i-].y) * L);
}
sort(p, p + n, cmpx);
ans = max(ans, calc());
for(int i = ; i < n; i++) p[i].x *= -;
reverse(p, p + n);
printf("%d\n", max(ans, calc())); return ;
}

vijos1055 奶牛浴场的更多相关文章

  1. Vijos1055 奶牛浴场(极大化思想求最大子矩形)

    思路详见 王知昆<浅谈用极大化思想解决最大子矩形问题> 写得很详细(感谢~....) 因为不太会用递推,所以用了第一种方法,时间复杂度是O(n^2),n为枚举的点数,对付这题绰绰有余 思路 ...

  2. P1578 奶牛浴场

    P1578 奶牛浴场 题目描述 由于John建造了牛场围栏,激起了奶牛的愤怒,奶牛的产奶量急剧减少.为了讨好奶牛,John决定在牛场中建造一个大型浴场.但是John的奶牛有一个奇怪的习惯,每头奶牛都必 ...

  3. 洛谷P1578 奶牛浴场

    P1578 奶牛浴场 题目描述 由于John建造了牛场围栏,激起了奶牛的愤怒,奶牛的产奶量急剧减少.为了讨好奶牛,John决定在牛场中建造一个大型浴场.但是John的奶牛有一个奇怪的习惯,每头奶牛都必 ...

  4. 洛谷1578:[WC2002]奶牛浴场——题解

    https://www.luogu.org/problemnew/show/P1578#sub 由于John建造了牛场围栏,激起了奶牛的愤怒,奶牛的产奶量急剧减少.为了讨好奶牛,John决定在牛场中建 ...

  5. [WC2002][洛谷P1578]奶牛浴场

    洛谷题解里那个人可真是话多呢. 题目描述 由于John建造了牛场围栏,激起了奶牛的愤怒,奶牛的产奶量急剧减少.为了讨好奶牛,John决定在牛场中建造一个大型浴场.但是John的奶牛有一个奇怪的习惯,每 ...

  6. Vijos 1055 奶牛浴场

    Description 求一个不覆盖指定点的最大子矩阵,\(n,m \leqslant 3\times 10^5,S \leqslant 5\times 10^3\) . Sol 没有名字的算法都叫x ...

  7. vijos P1055奶牛浴场&& Winter Camp2002

    这道题是我在寒假的模拟赛里碰到的,现在想起来仍觉得余味无穷.题目大意大致如下:给你一个矩形并在其中划出一个最大的子矩形,当然,在这个矩形里有些地方是取不到的,也就是说我们划的这个子矩形不能包含这些点( ...

  8. 洛谷 [P1578] WC2002 奶牛浴场

    本题是一道用极大化思想求最大子矩阵的经典题目.这个题目很出名,可以在百度搜索王知昆国家队dalao的论文,其中说的非常详细. 先枚举极大子矩形的左边界,然后从左到右依次扫描每一个障碍点,并不断修改可行 ...

  9. luogu P1578 奶牛浴场

    很好的一道题 王知昆爷爷的论文(讲的特别清楚) https://wenku.baidu.com/view/bc8311f69e314332396893f7.html 先贴上AC代码 #include& ...

随机推荐

  1. WPF 带CheckBox、图标的TreeView

    WPF 带CheckBox.图标的TreeView 在WPF实际项目开发的时候,经常会用到带CheckBox的TreeView,虽然微软在WPF的TreeView中没有提供该功能,但是微软在WPF中提 ...

  2. Spring面试笔记

    1. Spring工作机制及为什么要用?Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.Spring既是一个AOP框架,也是一IOC容器.SpringFramework的组成: ...

  3. Android Activity 管理

  4. 移除Sourcesafe与VC6的绑定

    整理日: 2015年2月16日 HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Source Control\Disabled

  5. 转:etcd:从应用场景到实现原理的全方位解读

    原文来自于:http://www.infoq.com/cn/articles/etcd-interpretation-application-scenario-implement-principle ...

  6. scala 安装

    http://www.scala-lang.org/download/install.html http://zh.scala-tour.com/#/hello-wolrd scala指南 To ru ...

  7. poj 2778 DNA Sequence AC自动机

    DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11860   Accepted: 4527 Des ...

  8. [BZOJ 2127] happiness 【最小割】

    题目链接:BZOJ - 2127 题目分析 首先,每个人要么学文科,要么学理科,所以可以想到是一个最小割模型. 我们就确定一个人如果和 S 相连就是学文,如果和 T 相连就是学理. 那么我们再来确定建 ...

  9. German Collegiate Programming Contest 2013:E

    数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...

  10. Angular 2 npm start 报错

    首先, index.html 和styles.css是和app目录平级的, 不要扔到里面去, 否则会404 确认配置文件齐全, 路径都正确之后 npm start What?! 照着快速起步也会弄错吗 ...