Integral Function
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 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 1
1 2
2 8
Sample Output
0
6593
-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;
}