其他分享
首页 > 其他分享> > 2018徐州预选赛

2018徐州预选赛

作者:互联网

大意就是每次给一个矩形就会覆盖之前的矩形的部分,且保证(x [ i ] <= x [ j ] y [ i ] <= y [ j ] )不同时出现,那么就是用一个set存一下x和y,逆序,对于每次的x或者y,如果是比当前最小的还要小,那么就是直接加上这个数,否则就是找当前set里面比他小的离他最近的那一个。

  1. lower_bound 要用 set.lower_bound
  2. 如果是原来是升序排列的话,lower_bound ( begin , end , num ) 那么lower_bound 找的是大于等于num的,upper_bound 找的是小于num的;如果原来事降序排列的话,lower_bound ( begin , end , num , greater () ) 那么lower_bound 找的是小于等于num的,upper_bound找的是大于num的
# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int MAXN=5e4+100;
int x[MAXN],y[MAXN];
set<int> xx,yy;
int main()
{
	int n;
	LL cnt=0;
	set<int>::iterator itx,ity;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
	}
	
	xx.insert(0),yy.insert(0);
	for(int i=n;i>=1;i--){
		if(i==n){
			xx.insert(x[i]);
			yy.insert(y[i]);
			cnt+=x[i];
			cnt+=y[i];
		}else{
			itx=xx.lower_bound(x[i]);
			itx--;
			cnt+=(x[i]-*(itx));
			xx.insert(x[i]);
			
			ity=yy.lower_bound(y[i]);
			ity--;
			cnt+=(y[i]-*(ity));
			yy.insert(y[i]);
		}
	}
	
	printf("%lld\n",cnt);
	return 0;
}

标签:lower,cnt,int,徐州,bound,xx,num,2018,预选赛
来源: https://www.cnblogs.com/fengzlj/p/15941171.html