Poj 1151 Atlanta (discretization + scanning line)

Source: Internet
Author: User

Question:

Calculates the total area of the sum of N rectangles. Http://poj.org/problem? Id = 1151

Referring to the discretization pages in the black book, I thought of the polygon Filling Algorithm in computer graphics I learned last semester.

SRC:

/*************************************** * **************************** Created: created: 28: 3: 2013 11: 43 filename: H: \ Pe \ USA \ poj.1151.atlanta. cppfile path: H: \ Pe \ usafile base: poj.1151.atlanta tisfile Ext: cppauthor: justme0 (http://blog.csdn.net/Justme0) Purpose: http://poj.org/problem? Id = 1151 calculates the total area of the rectangle ******************************* **************************************// /# define online_judge # DEFINE _ crt_secure_no_warnings # include <iostream> # include <algorithm> # include <vector> # include <string> # include <cassert> using namespace STD; // horizontal line segment struct horizon {double XL; // The horizontal double XR of the Left endpoint; // The horizontal double y of the right endpoint; // The horizontal bool ISUP of the horizontal line; // horizon (): XL (0), XR (0), y (0), ISUP (false ){} Horizon (double _ XL, double _ XR, double _ y, bool _ ISUP): XL (_ XL), XR (_ xr), y (_ y ), ISUP (_ ISUP) {} bool operator <(const horizon & Other) const {return this-> Y <Other. Y ;}}; // return: whether the input ends bool input (vector <double> & xvec, vector 

I can see on the Internet that some acmer divides the program into three layers: input, problem solving, and output. I think it is quite good. I plan to do the same in the future, so that it will not be fully squeezed into a main, this also facilitates debugging. I try not to use global variables, so that the message transmission is very clear during function calls.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.