程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> POJ訓練計劃1177_Picture(掃描線/線段樹+離散)

POJ訓練計劃1177_Picture(掃描線/線段樹+離散)

編輯:C++入門知識

POJ訓練計劃1177_Picture(掃描線/線段樹+離散)


解題報告

題意:

求矩形周長和。

思路:

左掃上掃,掃過了。

#include 
#include 
#include 
#include 
#include 
using namespace std;
struct Seg {
    int lx,rx,ly,ry,h,v;
    friend bool operator < (Seg a,Seg b)
    {
        return a.hr||qr>1;
    update1(rt<<1,l,mid,ql,qr,v);
    update1(rt<<1|1,mid+1,r,ql,qr,v);
    push_up1(rt,l,r);
}
void push_up2(int rt,int l,int r)
{
    if(lz[rt]) {
        sum[rt]=_hy[r+1]-_hy[l];
    } else sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void update2(int rt,int l,int r,int ql,int qr,int v)
{
    if(ql>r||qr>1;
    update2(rt<<1,l,mid,ql,qr,v);
    update2(rt<<1|1,mid+1,r,ql,qr,v);
    push_up2(rt,l,r);
}
int main()
{
    int lx,rx,ly,ry,n,i,j;
    scanf("%d",&n);
    for(i=0; i

Picture Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 10332 Accepted: 5485

Description

A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wall. Their sides are all vertical or horizontal. Each rectangle can be partially or totally covered by the others. The length of the boundary of the union of all rectangles is called the perimeter.

Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.
\

The cZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcnJlc3BvbmRpbmcgYm91bmRhcnkgaXMgdGhlIHdob2xlIHNldCBvZiBsaW5lIHNlZ21lbnRzIGRyYXduIGluIEZpZ3VyZSAyLiA8YnI+CjxjZW50ZXI+PGltZyBzcmM9"http://www.2cto.com/uploadfile/Collfiles/20140813/20140813085758254.jpg" alt="\">
The vertices of all rectangles have integer coordinates.

Input

Your program is to read from standard input. The first line contains the number of rectangles pasted on the wall. In each of the subsequent lines, one can find the integer coordinates of the lower left vertex and the upper right vertex of each rectangle. The values of those coordinates are given as ordered pairs consisting of an x-coordinate followed by a y-coordinate.

0 <= number of rectangles < 5000
All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.

Output

Your program is to write to standard output. The output must contain a single line with a non-negative integer which corresponds to the perimeter for the input rectangles.

Sample Input

7
-15 0 5 10
-5 8 20 25
15 -4 24 14
0 -6 16 4
2 15 10 22
30 10 36 20
34 0 40 16

Sample Output

228

Source

IOI 1998

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved