Sicily 1466. Taunt Exposure Estimation

本文介绍了一种估算骑士在攻城过程中遭受侮辱总量的方法。由于侮辱强度随时间和距离变化,并且测量数据不连续且随机,故采用梯形法则进行积分估算。

1466. Taunt Exposure Estimation

Constraints

Time Limit: 5 secs, Memory Limit: 32 MB

Description

The brave knights (kə’ nig’ əts) 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
· n pairs of floating point numbers (given in increasing x order), separated by a comma — in other words, a CSV file that could be input for a spreadsheet program [the first number is the x coordinate (time specification), the second is the y coordinate (the radiation reading)]

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):
0.00 to 365.25: 2099.8021

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

// Problem#: 1466
// Submission#: 3316720
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <string>
#include <queue>
#include <set>
#include <iomanip>
#include <map>
using namespace std;

const int MAX_N = 10000;

int main() {

    //std::cout.sync_with_stdio(false);

    int n;
    scanf("%d", &n);
    double xy[MAX_N][2];
    char temp;
    for (int i = 0; i < n; i++) {
        scanf("%lf%c%lf", &xy[i][0], &temp, &xy[i][1]);
    }
    double ans = 0;
    for (int i = 1; i < n; i++) ans += (xy[i][1] + xy[i - 1][1]) * (xy[i][0] - xy[i - 1][0]) / 2;
    printf("%.2lf to %.2lf: %.4lf\n", xy[0][0], xy[n - 1][0], ans);

    return 0;
}                                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值