日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【数学】Floating-Point Hazard

發布時間:2025/3/8 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【数学】Floating-Point Hazard 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Floating-Point Hazard

時間限制: 1 Sec 內存限制: 128 MB
提交: 106 解決: 42
[提交] [狀態] [命題人:admin]

題目描述

Given the value of low, high you will have to find the value of the following expression:

If you try to find the value of the above expression in a straightforward way, the answer may be incorrect due to precision error.

輸入

The input file contains at most 2000 lines of inputs. Each line contains two integers which denote the value of low, high (1 ≤ low ≤ high ≤ 2000000000 and high-low ≤ 10000). Input is terminated by a line containing two zeroes. This line should not be processed.

輸出

For each line of input produce one line of output. This line should contain the value of the expression above in exponential format. The mantissa part should have one digit before the decimal point and be rounded to five digits after the decimal point. To be more specific the output should be of the form d.dddddE-ddd, here d means a decimal digit and E means power of 10. Look at the output for sample input for details. Your output should follow the same pattern as shown below.

樣例輸入

1 100
10000 20000
0 0

樣例輸出

3.83346E-015
5.60041E-015

題目大意:

輸入兩個整數lllrrr,求∑i=lr((i+10?15)3?i3)\sum_{i=l}^r(\sqrt[3]{(i+10^{-15})}-\sqrt[3]{i})i=lr?(3(i+10?15)??3i?)的值,并用d.dddddE-ddd的格式輸出。

解題思路:

首先,我們可以先回顧一下求導的公式:f(x)′=f(x+Δx)?f(x)Δxf(x)\prime=\frac{f(x+\Delta x)-f(x)}{\Delta x}f(x)=Δxf(x+Δx)?f(x)?,因此當f(x)=x3,Δx=10?15f(x)=\sqrt[3]{x},\Delta x=10^{-15}f(x)=3x?Δx=10?15時,f(x)′=x+10?153?x310?15f(x)\prime=\frac{\sqrt[3]{x+10^{-15}}-\sqrt[3]x}{10^{-15}}f(x)=10?153x+10?15??3x??,因此∑i=lr((i+10?15)3?i3)=∑i=1rf(x)′?10?15\sum_{i=l}^r(\sqrt[3]{(i+10^{-15})}-\sqrt[3]{i})=\sum_{i=1}^rf(x)\prime*10^{-15}i=lr?(3(i+10?15)??3i?)=i=1r?f(x)?10?15
而此題主要就是因為根號里面的值太小,可能導致計算后為0,所以我們可以先算出∑i=1rf(x)′\sum_{i=1}^rf(x)\primei=1r?f(x)的值,10?1510^{-15}10?15可以直接先放在指數上,最后化簡為所需要的形式即可。

代碼:

#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> #include <sstream> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; #define inf 0x3f3f3f3f #define rep(i,l,r) for(int i=l;i<=r;i++) #define lep(i,l,r) for(int i=l;i>=r;i--) #define ms(arr) memset(arr,0,sizeof(arr)) //priority_queue<int,vector<int> ,greater<int> >q; const int maxn = (int)1e5 + 5; const ll mod = 1e9+7; int main() {#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int l,r;while(scanf("%d %d",&l,&r)&&l+r) {double t=0;for(int i=l;i<=r;i++) {t+=(1.0/3.0)*(pow(double(i),-2.0/3.0));}double x=0;int y=-15;while(t>10.0) {t=t/10.0;y++;}x=t;while(t<1.0) {t=t*10.0;y--;}x=t;printf("%.5fE-%03d\n",x,(-y));}return 0; }

總結

以上是生活随笔為你收集整理的【数学】Floating-Point Hazard的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。