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.