csu 1742 Integral Function(分区间求积分)

来源:互联网 发布:hbase删除一条数据 编辑:程序博客网 时间:2024/04/29 21:43

Integral Function

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 78  Solved: 26
[Submit][Status][Web Board]

Description

In mathematics, several function are unable to integral. For example:

But you can get the answer by computer.

Input

There are no more than T (T<=30) cases. Each case include two integer a, b (0<a <= b<=10).

Output

Each case output an answer.

(Please output the answer by ‘‘ printf (“%d\n”,(int)(answer*10000)) ‘‘ ).

Sample Input

1 11 22 8

Sample Output

06593-312
题意:求

思路:这是个典型的不可积函数,然后观察发现a和b都比较小,那么我们分区间,把所有矩形加起来即可得到近似值

代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main(){    double a,b;    while(~scanf("%lf %lf",&a,&b))    {        if(a==b)        {            printf("0\n");            continue;        }        double ans=0.0,d=(b-a)/100000;        while(a<=b)        {            ans=ans+sin(a)/a*d;            a+=d;        }        printf("%d\n",(int)(ans*10000));    }    return 0;}





0 0
原创粉丝点击