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

博客介绍了ACM竞赛中关于'csu 1742 Integral Function'的问题,该问题涉及计算某些无法直接积分的数学函数。通过将积分区间细分为多个小矩形并求和,可以得到函数的近似值。题目给出的输入输出格式及样例展示了问题的具体细节,解题思路是通过计算机分区间累加矩形面积来估算答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 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;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值