Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3132
Problem descriptionthe brave knights of Camelot are constantly exposed to French taunting while assaulting the castle occupied by the French. consequently, the taunting to which they are exposed varies with their distance from the castle during their assault, as well as variations in French taunting activity. we need to estimate the total amount of taunting that they are exposed to during a certain time period. unfortunately, we only have access to a set of measurements at random times-we do not have a continuous reading-and, because of flaws in our archaic equipment, the measurements of taunting occur at unpredictable intervals.
The total amount of taunting will be given by the integral of the taunting intensity during the time period, as held in the observation data file. the amount of random noise, though, is fairly high, so that a simple trapezoid-Rule integration is all that is merited.
Input
A single number,N, Specifying the number of data points in the file
NPairs of Floating Point Numbers (given in increasing x order), separated by a comma-in other words, a csv file that cocould be input for a spreadsheet program [the first number is the X coordinate (time specification), the second is the Y coordinate (the radiation reading)]
Outputa single line of text giving the first and last x values (with two digits to the right of the decimal point ), and the computed integral (with four digits to the right of the decimal point), in the fashion shown below (which reflects the data shown in the graph ):
0.00 to 365.25: 2099.8021
[A reasonable value for the given input, (shown in the graph above), since the values range around 5 3/4, and 365.25*5.75 gives 2100.1875.]
Sample Input
90.0000, 0.51760.9869, 1.0001.596, 1.1142.370, 1.0062.904, 0.84813.506, 0.57603.996, 0.47755.004, 0.39456.283, 1.004
Sample output
0.00 to 6.28: 4.7288
Source2006 ACM-ICPC Pacific Northwest Region
Question:
A series of coordinates are given. The coordinates are connected into a line, and the area of the line and the polygon enclosed on the X axis is obtained!
PS:
Understanding the meaning of the question is a very simple area problem!
Divide the image into multiple trapezoid, and use the trapezoid area formula to calculate the area of each trapezoid and add it again!
The Code is as follows:
# Include <cstdio> # include <cstring> const int maxn = 10017; Double X [maxn], Y [maxn]; int main () {# define TT # ifndef TT freopen ("in.txt", "r", stdin); freopen ("out.txt", "W", stdout ); # endif // TT int N; while (~ Scanf ("% d", & N) {for (INT I = 0; I <n; I ++) {scanf ("% lf, % lf ", & X [I], & Y [I]) ;}double S = 0; For (INT I = 1; I <n; I ++) {S + = (Y [I] + Y [I-1]) * (X [I]-X [I-1])/2.0; // trapezoid} printf ("%. 2lf to %. 2lf: %. 4lf \ n ", X [0], X [n-1], S);} return 0 ;}
HDU 3132 taunt exposure estimation (Mathematics)