Codeforces 296C

  题目大意:给定长宽的矩形,执行n次操作,每次操作分两种类型,1.H型,水平切割,2.V型,竖直切割。对于每次切割,给定切割点,求出每次切割后最大的矩形面积

  思路:直接用STL中的set即可。

#include <iostream>
#include <set>
#include <cstdio>
using namespace std;
set<long long> x,y;// 记录长宽上各个切点
set<long long> lx,ly;// 记录长宽上各个线段长度
int sx[200010]={0},sy[200010]={0};// lx,ly中对应长度的数量
int main()
{
	long long w,h,n;
	scanf("%I64d%I64d%I64d",&w,&h,&n);getchar();
	x.insert(0);x.insert(w);
	y.insert(0);y.insert(h);
	lx.insert(w);ly.insert(h);sx[w]++;sy[h]++;//别忘了初始化sx和sy
	set<long long>::iterator ite;
	while(n--){
		char op;
		long long pos;
		scanf("%c%I64d",&op,&pos);getchar();
		if(op=='H'){
			ite=y.upper_bound(pos);
			long long h=*ite;
			long long l=*(--ite);
			if(sy[h-l]==1)// 加入长度h-l只有一个,则可删除ly中对应项
				ly.erase(h-l);
			sy[h-l]--;// 见去一个长为h-l的线段
			ly.insert(h-pos);ly.insert(pos-l);// 加入新线段
			sy[h-pos]++;sy[pos-l]++;
			y.insert(pos);// 添加新的切点
		}
		else{
			ite=x.upper_bound(pos);
			long long h=*ite;
			long long l=*(--ite);
			if(sx[h-l]==1)
				lx.erase(h-l);
			sx[h-l]--;
			lx.insert(h-pos);lx.insert(pos-l);
			sx[h-pos]++;sx[pos-l]++;
			x.insert(pos);
		}
		long long a=*(--lx.end()),b=*(--ly.end());
		printf("%I64d\n",a*b);
	}
	return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值