挺好的一道题呢

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. 神经网络中的XOR问题

    XOR问题 解决办法: 网络如图 其中激活函数 ReLU,令 即可解决XOR问题.

  2. 171. Excel Sheet Column Number(C++)

    171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...

  3. 谷歌的C++智能指针实现

    //智能指针基类所有智能指针对象都继承该类class RefCountedBase { public: ; ; protected: virtual ~RefCountedBase(){} }; 智能 ...

  4. php ob_ 开头的相关函数

    <?phpbool ob_start([ callback $output_callback [, int $chunk_size [, bool $erase ]]]); /* 打开输出控制缓 ...

  5. PLSQL性能优化技巧

    1.理解执行计划1-1.什么是执行计划 oracle数据库在执行sql语句时,oracle的优化器会根据一定的规则确定sql语句的执行路径,以确保sql语句能以最优性能执行.在oracle数据库系统中 ...

  6. RBM 与 DBN 学习笔记

    2006 年,Hinton 等人基于受限波尔兹曼机(Re- stricted Boltzmann Machines, RBMs)提出的深度信念 网络(Deep Belief Networks, DBN ...

  7. OOS升级服务

    给我们的应用程序做个版本更新服务,展示一个安装程序如何实现自动更新. //服务组,添加需要的任何服务 public enum ServerEnum { AutoupdateService,//自动升级 ...

  8. code jam训练

    https://code.google.com/codejam/contests.html http://student.csdn.net/mcs/programming_challenges

  9. ZeroBraneStudio之支持GBK文件编码

    费了好大劲终于搞定了让ZBS支持打开GBK文件了.记录下过程: 看源码发现ZBS打开文件时会调用src\editor\commands.lua中的LoadFile函数,代码如下: local file ...

  10. bzoj 1040: [ZJOI2008]骑士 環套樹DP

    1040: [ZJOI2008]骑士 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1755  Solved: 690[Submit][Status] ...