codeForces 35E

本文深入探讨了AI音视频处理领域中的关键技术——视频分割与语义识别,通过详细解释这些技术的工作原理、应用场景及实际应用案例,为读者提供了一次全面的技术解读之旅。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

input
input.txt
output
output.txt

No Great Victory anniversary in Berland has ever passed without the war parade. This year is not an exception. That’s why the preparations are on in full strength. Tanks are building a line, artillery mounts are ready to fire, soldiers are marching on the main square... And the air forces general Mr. Generalov is in trouble again. This year a lot of sky-scrapers have been built which makes it difficult for the airplanes to fly above the city. It was decided that the planes should fly strictly from south to north. Moreover, there must be no sky scraper on a plane’s route, otherwise the anniversary will become a tragedy. The Ministry of Building gave the data on n sky scrapers (the rest of the buildings are rather small and will not be a problem to the planes). When looking at the city from south to north as a geometrical plane, the i-th building is a rectangle of height hi. Its westernmost point has the x-coordinate of li and the easternmost — of ri. The terrain of the area is plain so that all the buildings stand on one level. Your task as the Ministry of Defence’s head programmer is to find anenveloping polyline using the data on the sky-scrapers. The polyline’s properties are as follows:

  • If you look at the city from south to north as a plane, then any part of any building will be inside or on the boarder of the area that the polyline encloses together with the land surface.
  • The polyline starts and ends on the land level, i.e. at the height equal to 0.
  • The segments of the polyline are parallel to the coordinate axes, i.e. they can only be vertical or horizontal.
  • The polyline’s vertices should have integer coordinates.
  • If you look at the city from south to north the polyline (together with the land surface) must enclose the minimum possible area.
  • The polyline must have the smallest length among all the polylines, enclosing the minimum possible area with the land.
  • The consecutive segments of the polyline must be perpendicular.

Picture to the second sample test (the enveloping polyline is marked on the right).

Input

The first input line contains integer n (1 ≤ n ≤ 100000). Then follow n lines, each containing three integers hiliri (1 ≤ hi ≤ 109,  - 109 ≤ li < ri ≤ 109).

Output

In the first line output integer m — amount of vertices of the enveloping polyline. The next m lines should contain 2 integers each — the position and the height of the polyline’s vertex. Output the coordinates of each vertex in the order of traversing the polyline from west to east. Remember that the first and the last vertices of the polyline should have the height of 0.

Sample Input

Input
2
3 0 2
4 1 3
Output
6
0 0
0 3
1 3
1 4
3 4
3 0
Input
5
3 -3 0
2 -1 1
4 2 4
2 3 7
3 6 8
Output
14
-3 0
-3 3
0 3
0 2
1 2
1 0
2 0
2 4
4 4
4 2
6 2
6 3
8 3
8 0
//PS:以下是错误的。。
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 100008
struct Building
{
	int h,l,r;
}bd[maxn];
struct Edge
{
	int sx,sy,tx,ty;
}edge[4*maxn];
bool cmp(Building a,Building b)
{
	if(a.l<b.l)return 1;
	if(a.l>b.l)return 0;
	if(a.l==b.l)
	{
		if(a.h>b.h) return 1;
		if(a.h<b.h) return 0;
		if(a.h==b.h) 
		{
			if(a.r>=b.r) return 1;
			if(a.r<b.r) return 0;
		}
	}
}
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&bd[i].h,&bd[i].l,&bd[i].r);
		}
		sort(bd+1,bd+n+1,cmp);//城市排序完毕,接下来是建立边
		//建立边需要遍历每个城市
		edge[1].sx=bd[1].l;
		edge[1].sy=0;
		edge[1].tx=bd[1].l;
		edge[1].ty=bd[1].h;//
		edge[2].sx=bd[1].l;
		edge[2].sy=bd[1].h;
		edge[2].tx=bd[1].r;
		edge[2].ty=bd[1].h;//
		edge[3].sx=bd[1].r;
		edge[3].sy=bd[1].h;
		edge[3].tx=bd[1].r;//
		edge[3].ty=0;
		int m=3;
		for(int i=2;i<=n;i++)//遍历每个建筑物
		{
			if(bd[i].l>edge[m].tx)//如果左边在最后一边的右边
			{
				int mm=m;
				edge[++m].sx=edge[mm].tx;
				edge[m].sy=0;
				edge[m].tx=bd[i].l;
				edge[m].ty=0;
				edge[++m].sx=bd[i].l;
				edge[m].sy=0;
				edge[m].tx=bd[i].l;
				edge[m].ty=bd[i].h;
				edge[++m].sx=bd[i].l;
				edge[m].sy=bd[i].h;
				edge[m].tx=bd[i].r;
				edge[m].ty=bd[i].h;
				edge[++m].sx=bd[i].r;
				edge[m].sy=bd[i].h;
				edge[m].tx=bd[i].r;
				edge[m].ty=0;
			}
			else if(bd[i].l==edge[m].tx)//边重合//////////////////////////////
			{
				if(bd[i].h==edge[m].sy)//高度相等
				{
					m--;
					edge[m].tx=bd[i].r;
					edge[m].ty=bd[i].h;
					edge[++m].sx=bd[i].r;
					edge[m].sy=bd[i].h;
					edge[m].tx=bd[i].r;
					edge[m].ty=0;
				}
				else if(bd[i].h>edge[m].sy)//如果高度比最后一边的高度要高
				{
					edge[m].tx=bd[i].l;
					edge[m].ty=bd[i].h;
					edge[++m].sx=bd[i].l;
					edge[m].sy=bd[i].h;
					edge[m].tx=bd[i].r;
					edge[m].ty=bd[i].h;
					edge[++m].sx=bd[i].r;
					edge[m].sy=bd[i].h;
					edge[m].tx=bd[i].r;
					edge[m].ty=0;
				}
				else//如果高度比最后一边的高度要矮
				{
					edge[m].tx=bd[i].l;
					edge[m].ty=bd[i].h;
					edge[++m].sx=bd[i].l;
					edge[m].sy=bd[i].h;
					edge[m].tx=bd[i].r;
					edge[m].ty=bd[i].h;
					edge[++m].sx=bd[i].r;
					edge[m].sy=bd[i].h;
					edge[m].tx=bd[i].r;
					edge[m].ty=0;
				}
			}
			else //建筑的左边在最后一边的左边,注意全包含的情况
			{
				
				if(bd[i].h==edge[m].sy)//如果高度相同
				{
					if(bd[i].r<=edge[m].tx)//如果右边被包含在里
					{
						continue;
					}
					else //右边有突出
					{
						m--;
						edge[m].tx=bd[i].r;
						edge[m].ty=bd[i].h;
						edge[++m].sx=bd[i].r;
						edge[m].sy=bd[i].h;
						edge[m].tx=bd[i].r;
						edge[m].ty=0;
					}
				}
				else if(bd[i].h>edge[m].sy)//如果建筑的高度左边在最后一边的左边,且高度比他大
				{
					int hei=edge[m].sy;
					int rr=edge[m].tx;
					m--;
					edge[m].tx=bd[i].l;
					edge[m].ty=hei;
					edge[++m].sx=bd[i].l;
					edge[m].sy=hei;
					edge[m].tx=bd[i].l;
					edge[m].ty=bd[i].h;
					edge[++m].sx=bd[i].l;
					edge[m].sy=bd[i].h;
					edge[m].tx=bd[i].r;
					edge[m].ty=bd[i].h;
					if(bd[i].r>=rr)
					{
						edge[++m].sx=bd[i].r;
						edge[m].sy=bd[i].h;
						edge[m].tx=bd[i].r;
						edge[m].ty=0;
					}
					else
					{
						edge[++m].sx=bd[i].r;
						edge[m].sy=bd[i].h;
						edge[m].tx=bd[i].r;
						edge[m].ty=hei;
						edge[++m].sx=bd[i].r;
						edge[m].sy=hei;
						edge[m].tx=rr;
						edge[m].ty=hei;
						edge[++m].sx=rr;
						edge[m].sy=hei;
						edge[m].tx=rr;
						edge[m].ty=0;
					}
				}
				else //如果建筑左边在最后一边的左边,且高度比其要小
				{
					if(bd[i].r<=edge[m].tx)//如果右边被包含在里
					{
						continue;
					}
					edge[m].ty=bd[i].h;
					int ll=edge[m].tx;
					edge[++m].sx=ll;
					edge[m].sy=bd[i].h;
					edge[m].tx=bd[i].r;
					edge[m].ty=bd[i].h;
					edge[++m].sx=bd[i].r;
					edge[m].sy=bd[i].h;
					edge[m].tx=bd[i].r;
					edge[m].ty=0;
				}
			}
		}
		cout<<m+1<<endl;
		for(int i=1;i<=m;i++)
		{
			cout<<edge[i].sx<<" "<<edge[i].sy<<endl;
		}
		cout<<edge[m].tx<<" "<<edge[m].ty<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值