Codeforces 528A Glass Carving STL模拟

题目链接:点击打开链接

题意:

给定n*m的矩阵,k个操作

2种操作:

1、H x 横向在x位置切一刀

2、V y 竖直在y位置切一刀

每次操作后输出最大的矩阵面积

思路:

因为行列是不相干的,所以只要知道每次操作后行的最大间距和列的最大间距,相乘就是最大面积

用一个set维护横向的所有坐标点,一个multiset维护横向的间距。

每次对行操作x则在set中找到比x大的最小数 r 和比x小的最大数l ,操作前的间距dis = r-l,在multiset中删除dis并插入r-x 和x-l。再在set中插入x

对列操作同理。

操作完后取行列各自的最大间距相乘即可,注意相乘可能爆int

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
const int N = 105;

int heheeh;
template <class T>
inline bool rd(T &ret) {
    char c; int sgn;
    if (c = getchar(), c == EOF) return 0;
    while (c != '-' && (c<'0' || c>'9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
template <class T>
inline void pt(T x) {
    if (x <0) {
        putchar('-');
        x = -x;
    }
    if (x>9) pt(x / 10);
    putchar(x % 10 + '0');
}
struct node {
    int l, r, len;

};
multiset<int> h, c;
set<int> hh, cc;
set<int>::iterator it;
multiset<int>::iterator itx, ity;
int main() {
    int n, m, k, x;
    char a[5];
    scanf("%d%d%d", &m, &n, &k);

    hh.insert(0); hh.insert(m);
    h.insert(m);
    cc.insert(0); cc.insert(n);
    c.insert(n);
    while (k-- > 0) {
        scanf("%s %d", a, &x);
            if (a[0] == 'H') {
            it = cc.upper_bound(x);
            int r = *it; int l = *(--it);
            c.erase(c.lower_bound(r - l));
            c.insert(r - x);
            c.insert(x - l);
            cc.insert(x);
        }
        else {
            it = hh.upper_bound(x);
            int r = *it; int l = *(--it);
            h.erase(h.lower_bound(r - l));
            h.insert(r - x);
            h.insert(x - l);
            hh.insert(x);
        }
        itx = h.end();
        ity = c.end();
        printf("%I64d\n", (ll)(*(--itx))*(*(--ity)));
    }
    return 0;
}
时间: 2024-12-17 19:22:40

Codeforces 528A Glass Carving STL模拟的相关文章

Codeforces 527C Glass Carving(Set)

题意  一块w*h的玻璃  对其进行n次切割  每次切割都是垂直或者水平的  输出每次切割后最大单块玻璃的面积 用两个set存储每次切割的位置   就可以比较方便的把每次切割产生和消失的长宽存下来  每次切割后剩下的最大长宽的积就是答案了 #include <bits/stdc++.h> using namespace std; const int N = 200005; typedef long long LL; set<int>::iterator i, j; set<i

Codeforces 527C Glass Carving

vjudge 上题目链接:Glass Carving 题目大意: 一块 w * h 的玻璃,对其进行 n 次切割,每次切割都是垂直或者水平的,输出每次切割后最大单块玻璃的面积: 用两个 set 存储每次切割的位置,就可以比较方便的把每次切割产生和消失的长宽存下来(用个 hash 映射数组记录下对应值的长宽的数量即可,O(1) 时间维护),每次切割后剩下的最大长宽的积就是答案了: 1 #include<cstdio> 2 #include<cstring> 3 #include<

Codeforces 527C Glass Carving (最长连续0变形+线段树)

Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm ?×? h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what t

Codeforces 527A Glass Carving

题意:给你一张长方形的纸,你每一次撕掉最大的那个正方形,然后剩下来一块矩形,再继续对剩下的矩形进行这个操作,一直到这个剩下的矩形是个正方形. 解题思路:递归 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月18日 星期三 00时41分16秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #inclu

HDU 4028 The time of a day STL 模拟题

暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define ll __int64 #define N 42 ll n,m,ans;

Codeforces 475C Kamal-ol-molk&#39;s Painting 模拟

题目链接:点击打开链接 题意:给定n*m的矩阵 X代表有色 .代表无色 用一个x*y的矩阵形刷子去涂色. 刷子每次可以→或↓移动任意步. 若能够染出给定的矩阵,则输出最小的刷子的面积 若不能输出-1 思路: 先找到连续最小的x,y 因为至少一个边界和x或y相等,所以枚举(x,i) 和 (i,y)就可以了. #pragma comment(linker, "/STACK:102400000,102400000") #include <stdio.h> #include <

HDU 4022 Bombing STL 模拟题

手动模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define N 10100 #define inf 1000000010 map<

C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用)

C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a re

stl+模拟 CCF2016 4 路径解析

1 // stl+模拟 CCF2016 4 路径解析 2 // 一开始题意理解错了.... 3 4 #include <iostream> 5 #include <string> 6 #include <vector> 7 using namespace std; 8 void fre() {freopen("in.txt","r",stdin);} 9 vector<string> l; 10 int main(){