zoukankan      html  css  js  c++  java
  • 51nod 1562 玻璃切割 (set)

     1 #include<stdio.h>
     2 #include<iostream>
     3 #include<set>
     4 using namespace std;
     5 typedef long long LL;
     6 
     7 const int maxn = 200010;
     8 LL ans[maxn];
     9 int x[maxn];
    10 char c[maxn];
    11 set<int> row,col;
    12 set<int>:: iterator it;
    13 
    14 int main()
    15 {       
    16     int w, h, n, maxr, maxc;
    17     while(~scanf("%d%d%d", &w, &h, &n))
    18     {
    19         maxr = maxc = 0;
    20         row.clear();col.clear();
    21         row.insert(0);row.insert(h);
    22         col.insert(0);col.insert(w);
    23         for(int i =0 ;i < n;i++){
    24             scanf("%*c%c%d", &c[i], &x[i]);
    25             if(c[i] == 'H') row.insert(x[i]);
    26             else col.insert(x[i]);
    27         }
    28         int l, r;
    29         for(it = row.begin();it != row.end();){ 
    30             l = *it;
    31             it++;
    32             r = *it;
    33             maxr = max(maxr, r-l);
    34         }
    35         for(it = col.begin();it != col.end();){ 
    36             l = *it;
    37             it++;
    38             r = *it;                  
    39             maxc = max(maxc, r-l);
    40         }
    41         for(int i = n-1;i >= 0;i--){
    42             ans[i] = 1LL*maxr*maxc;
    43             if(c[i] == 'H'){
    44                 it = row.lower_bound(x[i]);
    45                 it--;
    46                 l = *it;
    47                 it++;it++;
    48                 r = *it;
    49                 maxr = max(maxr, r-l);
    50                 row.erase(x[i]);
    51             }
    52             else{
    53                 it = col.lower_bound(x[i]);
    54                 it--;
    55                 l = *it;
    56                 it++;it++;
    57                 r = *it;
    58                 maxc = max(maxc, r-l);
    59                 col.erase(x[i]);
    60             }
    61         }
    62         for(int i = 0;i < n;i++) 
    63             printf("%lld
    ", ans[i]);           
    64     }
    65     return 0;
    66 }
  • 相关阅读:
    poj 1466 Girls and Boys
    poj 1486 Sorting Slides
    poj 2112 Optimal Milking
    poj 1274 The Perfect Stall
    SHoj 420 购买装备
    poj 2987 Firing
    SHoj A序列
    FOJ Problem 2271 X
    XidianOJ 1028 数字工程
    XidianOJ 1030 三数和
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/9434344.html
Copyright © 2011-2022 走看看