• 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
  • 相关阅读:
    C平衡二叉树(AVL)创建和删除
    C格式字符串转为二叉树
    C前序遍历二叉树Morris Traversal算法
    C单链表操作
    C仿黑白棋版XO棋
    C传递参数给main函数
    C图形化第一步
    Perl看完这个,再不敢说自己会玩贪吃蛇
    Perl寻路A*算法实现
    C字符贪吃蛇
  • 原文地址:https://www.cnblogs.com/showson/p/5097851.html
Copyright © 2020-2023  润新知