首页 > 代码库 > HDU 3132 Taunt Exposure Estimation(数学)
HDU 3132 Taunt Exposure Estimation(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3132
Problem Description
The 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.
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
Output
A 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):
[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.]
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
9 0.0000, 0.5176 0.9869, 1.000 1.596, 1.114 2.370, 1.006 2.904, 0.8481 3.506, 0.5760 3.996, 0.4775 5.004, 0.3945 6.283, 1.004
Sample Output
0.00 to 6.28: 4.7288
Source
2006 ACM-ICPC Pacific Northwest Region
题意:
给出一系列的坐标,将坐标连成折线,求折线和到X轴围成的多边形的面积!
PS:
题意看懂了就是一道很简单的求面积的题!
把图形分成多块梯形,用梯形面积公式求每块梯形的面积再加一下就好!
代码如下:
#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;//梯形 } printf("%.2lf to %.2lf: %.4lf\n",x[0],x[n-1],s); } return 0; }
HDU 3132 Taunt Exposure Estimation(数学)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。