Rectilinear Regions+模拟

题目描述

A rectilinear path connecting two points in the plane is a path consisting of only horizontal and vertical line segments. A rectilinear path is said to be monotone with respect to the x-axis (resp., y-axis) if and only if its intersection with every vertical (resp., horizontal) line is either empty or a contiguous portion of that line. A staircase is a rectilinear path if it is monotone to both the x-axis and the y-axis, and a staircase is unbounded if it starts and ends with a semi-infinite horizontal segment, i.e., a segment that extends to infinity on both ends of the x-axis. Note that staircases can be either increasing or decreasing, depending on whether they go up or down as we move along them from left to right on the y-axis. A staircase with n vertical line segments is called a staircase with n steps.

Considering two unbounded staircases L and U, there can be several or no closed rectilinear regions bounded by staircases L and U. Among the closed rectilinear regions, some regions are bounded by a staircase L to the bottom and by a staircase U to the top. For example, in the following figure, the two regions colored yellow are that kind of closed rectilinear regions. We would like to compute the total area of such regions.

Figure G.1. Two staircases L and U, where U has 3-steps and L has 4-steps. The two yellow colored regions are closed rectilinear regions bounded by a staircase L to the bottom, and a staircase U to the top. The xiL,yiL (resp., xiU,yiU) are the x-, y-coordinates of corner points of the staircase L (resp., U).

y0 x1 y1 x2 y2 … xn yn  --------------------------------      (1)

where x1 < x2 < … < xn for x-coordinates of vertical line segments, and y0 < y1 < … < yn for y-coordinates of horizontal line segments of an increasing staircase or y0 > y1 > … > yn for a decreasing staircase.

For example, given a 4-step staircase L represented with

6 2 9 11 11 15 16 21 19

and a 3-step staircase U represented with

3 6 12 10 14 18 17

the number of bounded rectilinear regions is 2 and the total area of the regions is 32 (see figure G.1).

Given two unbounded staircases L and U that all x-coordinates represented in (1) of corner points of both L and U are unique, and all y-coordinates represented in (1) of corner points of both L and U are unique, compute the total area of bounded rectilinear regions that bounded by L to the bottom of the regions and by U to the top of the regions.

 

输入

Your program is to read from standard input. The first line contains two positive integers n and m, respectively, representing the number of steps of unbounded staircases L and U, where 1 ≤ n,m ≤ 25,000    25,000. The second (resp., third) line contains 2n + 1 (resp., 2m + 1) integers representing the x-, y-coordinates of corner points of the staircase L (resp., U), and the integers are sequenced in the order of the notation (1). The coordinates are represented with non-negative integers less than or equal to 50,000.

 

输出

Your program is to write to standard output. The first line should contain two integers k and w, where k represents the number of closed rectilinear regions and w represents the total area of those regions. If there is no such regions, then your program should write 0 for both k and w.

 

样例输入

4 3
6 2 9 11 11 15 16 21 19
3 6 12 10 14 18 17

 

样例输出

2 32
#include<bits/stdc++.h> 

using namespace std;
typedef long long ll;
int L,U,tot;

const int N=5e4+10;

struct node{
	int x,y,tp;
	bool operator<(const node &p)const{
		return x<p.x;
	}
}t[N];

int main(){
	int x,y,n,m;
	scanf("%d%d",&n,&m);
	scanf("%d",&L);
	for(int i=1;i<=n;i++)
	scanf("%d%d",&x,&y),t[++tot]=(node){x,y,0};
	
	scanf("%d",&U);
	for(int i=1;i<=m;i++)
	scanf("%d%d",&x,&y),t[++tot]=(node){x,y,1};
	
	sort(t+1,t+1+tot);
	ll sum=0,lx=-1,anx,any;
	anx=any=0;
	for(int i=1,pre=0,pos,flag;i<=tot;pre=pos){
		pos=t[i].x;
		if(L<U)sum+=(ll)(pos-pre)*(U-L),flag=0;
		else flag=1;
		for(;t[i].x==pos&&i<=tot;i++){
			if(t[i].tp==0)L=t[i].y;
			else U=t[i].y;
		}
		if(flag&&L<U)lx=pos;
		if(!flag&&L>=U){
			if(lx>=0){
				anx++;any+=sum;
			}
			sum=0;lx=pos;
		}
	}
	printf("%lld %lld\n",anx,any);
	return 0;
}




 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值