L

来源:互联网 发布:征途 巨人网络 编辑:程序博客网 时间:2024/05/17 08:08

//水题靠经验,一直wa,心疼
I guess that everybody has learned the course Calculus(微积分). To tell you the truth, I hate what course because of the endless exercise to do! My teacher was so strict that he assigned many exercise about polynomial integration to me. In each problem, he just gave me a polynomial f(x), starting point xs and ending point xt, and I must calculate the value of . I don’t want to waste my time on that, I need a efficient program to help me calculating that! My dear friend, can you help me?
Input
The first line of input contains an integer T, indicating test cases.
In each test case, the first line consist of 3 integers: n, xs, xt. N means that f(x) consists of n blocks:
Then following N lines of input, each line consists two integers: ai and di, representing the coefficient and degree of the i-th part of f(x), respectively.
1 <= n <= 10,
1 <= xs <= xt <= 100,
-3 <= di <= 3,
0 <= ai <= 20.
Output
In each test case, the output contains one line.
The only one line is formatted as “Case #X: Y”, where X is the test case number (starting with 1), Y is the result of , rounded to three decimal points.
Sample Input
2
2 1 2
2 1
3 2
1 1 5
1 0
Sample Output
Case #1: 10.000
Case #2: 4.000

#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<string>#include<algorithm>#include<stack>#include<queue>#include<cctype>using namespace std;const int MAX = 999999;const double Eps = 1e-12;const double PI = acos(-1.0);int gcd(int x, int y){    return x%y == 0 ? y : gcd(y, x%y);}struct node{    double a, b;}num[100];int main(){    int t;    double sum;    while (cin >> t)    {        for (int j = 1; j <= t; j++)        {            sum = 0;            double n, da, dt;            cin >> n >> da >> dt;            for (int i = 0; i < n; i++)                cin >> num[i].a >> num[i].b;            for (int i = 0; i < n; i++)            {                if (num[i].b >= 0)                {                    double aa = num[i].a, bb = num[i].b;                    num[i].a = aa / (bb + 1);                    num[i].b = bb + 1;                    sum += num[i].a*(pow(dt, num[i].b) - pow(da, num[i].b));                }                else                {                    if (num[i].b == -1)                        sum += num[i].a*(log(dt) - log(da));                    else                    {                        double aa = num[i].a, bb = num[i].b;                        num[i].a = aa / (bb + 1);                        num[i].b = bb + 1;                        sum += num[i].a*(pow(dt, num[i].b) - pow(da, num[i].b));                    }                }            }            printf("Case #%d: %.3lf\n", j, sum);        }    }    return 0;}
这里写代码片
0 0