POJ 1177 矩形周长并 扫描线

  • 计算当前扫描线上“进出”矩形的次数,乘上对应“事件”的边长。
/* 
 * File:   main.cpp
 * Author: semprathlon
 *
 * Created on April 26, 2016, 7:18 PM
 */

#include 
#include 
#include 
#include 
#include 

using namespace std;

struct Rectangle{
    int x1,y1,x2,y2;
    Rectangle(){}
    Rectangle(int _x1,int _y1,int _x2,int _y2):x1(_x1),x2(_x2),y1(_y1),y2(_y2){}
};

vector rects;

bool cmp(const int& a,const int& b){
    if (abs(a-b)<1e-5)
        return 0;
    return a-b<0;
}

int unionPerimeterY(const vector& rects){
    if (rects.empty()) return 0;
    typedef pair > Event;
    vector events;
    vector ys;
    for(int i=0;iy2) swap(y1,y2);
            sum[y1]+=delta;
            sum[y2]-=delta;
        
            int cnt=0,tmp=0;
            for(int j=0;j& rects){
    if (rects.empty()) return 0;
    typedef pair > Event;
    vector events;
    vector xs;
    for(int i=0;ix2) swap(x1,x2);
            sum[x1]+=delta;
            sum[x2]-=delta;
        
            int cnt=0,tmp=0;
            for(int j=0;j>n){
        if (!n) break;
        rects.clear();
        for(int i=0;i>x1>>y1>>x2>>y2;
            rects.push_back(Rectangle(x1,y1,x2,y2));
        }
        cout< 

POJ 1177 矩形周长并 扫描线

https://devblog.citruxonve.net/posts/9e6b295a/

Author

Semprathlon / Simfae Dean

Posted on

04/27/2016

Updated on

07/19/2023

Licensed under

Comments