• vijos1055 奶牛浴场


    挺好的一道题呢

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

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cstdlib>
     4 #include<algorithm>
     5 #include<iostream>
     6 
     7 using namespace std;
     8 
     9 void setIO(const string& s) {
    10     freopen((s + ".in").c_str(), "r", stdin);
    11     freopen((s + ".out").c_str(), "w", stdout);
    12 }
    13 
    14 template<typename Q> Q read(Q& x) {
    15     static char c, f;
    16     for(f = 0; c = getchar(), !isdigit(c); ) if(c == '-') f = 1;
    17     for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    18     return f && (x = -x), x;
    19 }
    20 template<typename Q> Q read() {
    21     static Q x; return read(x);
    22 }
    23 
    24 const int N = 5000 + 10;
    25 
    26 struct Node {
    27     int x, y;
    28     Node(int x = 0, int y = 0) : x(x), y(y) {}
    29 }p[N];
    30 
    31 bool cmpx(const Node& lhs, const Node& rhs) {
    32     return lhs.x < rhs.x;
    33 }
    34 
    35 bool cmpy(const Node& lhs, const Node& rhs) {
    36     return lhs.y < rhs.y;
    37 }
    38 
    39 int L, H, n;
    40 int calc() {
    41     int ans = 0;
    42     for(int i = 0; i < n; i++) {
    43         int U = H, D = 0;
    44         for(int j = i + 1; j < n; j++) {
    45             ans = max(ans, (p[j].x - p[i].x) * (U - D));
    46             if(D <= p[j].y && p[j].y <= U) {
    47                 if(p[j].y > p[i].y) U = p[j].y;
    48                 else D = p[j].y;
    49             }
    50             if(U == D) break;
    51         }
    52     }
    53     return ans;
    54 }
    55 
    56 int main() {
    57 #ifdef DEBUG
    58     freopen("in.txt", "r", stdin);
    59     freopen("out.txt", "w", stdout);
    60 #endif
    61     
    62     read(H), read(L), read(n);
    63     for(int i = 0; i < n; i++) {
    64         int x = read<int>(), y = read<int>();
    65         p[i] = Node(x, y);
    66     }
    67     p[n++] = Node(0, 0);
    68     p[n++] = Node(0, H);
    69     p[n++] = Node(L, 0);
    70     p[n++] = Node(L, H);
    71     
    72     int ans = 0;
    73     sort(p, p + n, cmpy);
    74     for(int i = 1; i < n; i++) {
    75         ans = max(ans, (p[i].y - p[i-1].y) * L);
    76     }
    77     sort(p, p + n, cmpx);
    78     ans = max(ans, calc());
    79     for(int i = 0; i < n; i++) p[i].x *= -1;
    80     reverse(p, p + n);
    81     printf("%d
    ", max(ans, calc()));
    82     
    83     return 0;
    84 }
    View Code
  • 相关阅读:
    表、栈和队列
    POJ 1207 The 3n + 1 problem
    记录一个很低级的错误:command 'usr/local/cuda/bin/vncc' failed with exit status 2
    [转载]Benchmark和baseline的区别
    [转载]神经网络架构搜索(Neural Architecture Search)杂谈
    CNN常用图片分类网络
    [转载]OCR原理
    目标检测、实例分割学习
    [转载]上采样
    自动驾驶资料收集
  • 原文地址:https://www.cnblogs.com/showson/p/5097851.html
Copyright © 2020-2023  润新知