2018 ICPC徐州网络赛 G.Trace 傻逼检测题

G.Trace

There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) means the wave is a rectangle whose vertexes are ( 00 , 00 ), ( xx , 00 ), ( 00 , yy ), ( xx , yy ). Every time the wave will wash out the trace of former wave in its range and remain its own trace of ( xx , 00 ) -> ( xx , yy ) and ( 00 , yy ) -> ( xx , yy ). Now the toad on the coast wants to know the total length of trace on the coast after n waves. It's guaranteed that a wave will not cover the other completely.

Input

The first line is the number of waves n(n \le 50000)n(n50000).

The next nn lines,each contains two numbers xxyy ,( 0 < x0<x , y \le 10000000y10000000 ),the ii-th line means the ii-th second there comes a wave of ( xx , yy ), it's guaranteed that when 1 \le i1i , j \le njn,x_i \le x_jxixj and y_i \le y_jyiyj don't set up at the same time.

Output

An Integer stands for the answer.

Hint:

As for the sample input, the answer is 3+3+1+1+1+1=103+3+1+1+1+1=10

样例输入

3
1 4
4 1
3 3

样例输出

10

傻逼题,傻逼做不出来的题。。。。。 QAQ
浓缩题意:不断给(0,0)位置覆盖长x宽y的矩形纸片,问最后露出来的边长长度之和是多少(x、y坐标轴不算)
重中之重的一点是:保证没有一个矩形会被完全覆盖,也就是说,有几个矩形,就会露出几个小“尖尖”,如图

那问题就很简单了(但我还是想不到):
1.从最后一块矩形开始从后向前遍历
2.横边和竖边分别算最后相加
3.对于横边:找到已遍历的边中距离当前边最近的一条(二分查找),给sum加上它们的高度差。竖边同理,给sum加上长度差

AC代码:

 
 

猜你喜欢

转载自www.cnblogs.com/Shepard/p/9625302.html