zoukankan      html  css  js  c++  java
  • 51nod1562(set&模拟)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1562

    题意:中文题诶~

    思路:直接用set模拟

    set<ll> stw, sth分别存储对应 'V' 对应的切割线位置和 'H'切割线对应的位置;
    multiset<ll> valuew, valueh分别存储每相邻两条 ‘V' 切割线的距离和每相邻两条 'H'切割线对应的距离;

    模拟过程:每切割一次,找到对应x前面一条切割线cnt1和后面一条切割线cnt2,将一个cnt2-cnt1从对应multiset中删除,并将cnt2-x和x-cnt1加入该multiset中;

    对应每次切割后的答案即为max(valuew)*max(valueh),过程很直观就不多说了;

    注意会爆int,被坑了....

    代码:

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <set>
     4 #define ll long long
     5 using namespace std;
     6 
     7 set<ll> stw, sth;
     8 multiset<ll> valuew, valueh;
     9 
    10 int main(void){
    11     ll w, h, n;
    12     multiset<ll>::iterator it;
    13     scanf("%lld%lld%lld", &w, &h, &n);
    14     valueh.insert(h);
    15     valuew.insert(w);
    16     stw.insert(0), stw.insert(w);
    17     sth.insert(0), sth.insert(h);
    18     while(n--){
    19         char str[5];
    20         ll x;
    21         scanf("%s%lld", str, &x);
    22         if(str[0]=='H'){
    23             it=sth.lower_bound(x);
    24             ll h1=*it;
    25             it--;
    26             ll h2=*it;
    27             it=valueh.find(h1-h2);
    28             valueh.erase(it);
    29             valueh.insert(x-h2);
    30             valueh.insert(h1-x);
    31             sth.insert(x);
    32         }else{
    33             it=stw.lower_bound(x);
    34             ll w1=*it;
    35             it--;
    36             ll w2=*it;
    37             it=valuew.find(w1-w2);
    38             valuew.erase(it);
    39             valuew.insert(x-w2);
    40             valuew.insert(w1-x);
    41             stw.insert(x);
    42         }
    43         ll fx=*(valueh.rbegin());
    44         ll fy=*(valuew.rbegin());
    45         printf("%lld
    ", fx*fy);
    46     }
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    匈牙利游戏
    钓鱼
    路由选择
    借教室
    有趣的数
    广告印刷
    海战
    暑假周进度报告(一)
    在Oracle创建一个自己用的用户及角色
    下载,安装oracle数据库以及navicat连接数据库
  • 原文地址:https://www.cnblogs.com/geloutingyu/p/6736091.html
Copyright © 2011-2022 走看看