题意:n*m的方格,“0 x”表示x轴在x位置切一刀,“0 y”表示y轴在y位置切一刀,每次操作后输出当前面积最大矩形。

思路:用set分别储存x轴y轴分割的点,用multiset(可重复)储存x轴y轴边,每次输出最大的长和最大的宽的积。题目可能重复切。multiset如果直接erase(13)会把所有的13都删掉,如果只想删一个则erase(multiset.find(13))。第一次知道set自带二分...

这里multiset也可以用map<int, int, greater<int> >,然后用迭代器指向最后一个key就行了

代码:

#include<set>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = + ;
const int seed = ;
const int MOD = + ;
const int INF = 0x3f3f3f3f;
set<ll> x, y;
multiset<ll> lenx, leny;
int main(){
int T;
ll n, m, q;
scanf("%d", &T);
while(T--){
scanf("%lld%lld%lld", &n, &m, &q);
x.clear();
y.clear();
lenx.clear();
leny.clear();
x.insert(),x.insert(n),lenx.insert(n);
y.insert(),y.insert(m),leny.insert(m);
set<ll>::iterator it;
while(q--){
ll o, p;
scanf("%lld%lld", &o, &p);
if(o == && x.count(p) == ){
it = x.lower_bound(p);
lenx.insert(*it - p);
int len = *it - *(--it);
lenx.erase(lenx.find(len));
lenx.insert(p - *it);
x.insert(p);
}
else if(o == && y.count(p) == ){
it = y.lower_bound(p);
leny.insert(*it - p);
int len = *it - *(--it);
leny.erase(leny.find(len));
leny.insert(p - *it);
y.insert(p);
}
it = lenx.end();
ll chang = *(--it);
it = leny.end();
ll kuan = *(--it);
printf("%lld\n", chang * kuan);
}
}
return ;
}

SPOJ ADAFIELD Ada and Field(STL的使用:set,multiset,map的迭代器)题解的更多相关文章

  1. STL——容器(Set & multiset)的迭代器

    1.set.insert(elem);     //在容器中插入元素. 2.set.begin();         //返回容器中第一个数据的迭代器. 3.set.end();          / ...

  2. SPOJ - ADAFIELD ,Set+map,STL不会超时!

    ADAFIELD - Ada and Field 这个题,如果用一个字来形容的话:-----------------------------------------------嗯! 题意:n*m的空白 ...

  3. STL笔记(1)map

    STL笔记(1)map STL之map ZZ from http://hi.baidu.com/liyanyang/blog/item/d5c87e1eb3ba06f41bd576cf.html 1. ...

  4. vector源码(参考STL源码--侯捷):空间分配导致迭代器失效

    vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...

  5. C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法

    每次忘记都去查,真难啊 /* C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法 */ /* vector常用用法 */ //头文件 #i ...

  6. STL中的Set和Map——入门新手篇

    STL中的Set和Map 先来看一段网络上的文字描述: 上图是一段关于STL中Set集合的描述,同样的,也近似适合Map的描述.上述文字中,描述了最为重要的特征: Set和Map,底层调用了红黑树的结 ...

  7. SPOJ:Ada and Orange Tree (LCA+Bitset)

    Ada the Ladybug lives near an orange tree. Instead of reading books, she investigates the oranges. T ...

  8. [SPOJ 30669] Ada and Trip

    [题目链接] https://www.spoj.com/problems/ADATRIP/ [算法] 直接使用dijkstra堆优化算法即可 [代码] #include<bits/stdc++. ...

  9. @spoj - ADAMOLD@ Ada and Mold

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 N 的序列 A,将其划分成 K + 1 段,划分 ...

随机推荐

  1. 聊一聊Linux中的工作队列

    2018-01-18 工作队列是Linux内核中把工作延迟执行的一种手段,其目的不同于软中断,软中断是提高CPU的响应,尽可能的缩短关中断的时间:而工作队列主要目的是节省资源,其比较适合很微小的任务, ...

  2. java.io.File实战

    There are many things that can go wrong: A class works in Unix but doesn't on Windows (or vice versa ...

  3. 【Python练习】文件引用用户名密码登录系统

    一.通过txt文件引入用户名密码 1 #coding=utf-8 from selenium import webdriver #from selenium.common.exceptions imp ...

  4. 为帝国cms模板添加站内搜索小教程

    由于客户的需要,最近都在整帝国cms,很多东西还是不熟悉,特别是帝国cms模板,以前用的那些网站模板一般是保存在ftp文件中,而帝国cms模板是直接保存在数据库中,修改是在网站后台的模板管理,得慢慢适 ...

  5. Python模块:配置文件解析器configparser

    版权声明:本文为博主皮皮http://blog.csdn.net/pipisorry原创文章,未经博主同意不得转载. https://blog.csdn.net/pipisorry/article/d ...

  6. ubuntu,windows 卸载安装mysql

    首先删除mysql: sudo apt-get remove mysql-* 1 然后清理残留的数据 dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dp ...

  7. PAT 1016 Phone Bills[转载]

    1016 Phone Bills (25)(25 分)提问 A long-distance telephone company charges its customers by the followi ...

  8. [LeetCode] 383. Ransom Note_Easy tag: Hash Table

    Given an arbitrary ransom note string and another string containing letters from all the magazines, ...

  9. testng入门教程3用TestNG执行case的顺序

    本教程介绍了TestNG中执行程序的方法,这意味着该方法被称为第一和一个接着.下面是执行程序的TestNG测试API的方法的例子. 创建一个Java类文件名TestngAnnotation.java在 ...

  10. 神经网络 java包

    java神经网络组件Joone.Encog和Neuroph https://github.com/deeplearning4j/deeplearning4j http://muchong.com/ht ...