生活随笔
收集整理的這篇文章主要介紹了
内部收益率(二分)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目描述
輸入
輸出
對(duì)于每組數(shù)據(jù),輸出僅一行,即項(xiàng)目的IRR,四舍五入保留小數(shù)點(diǎn)后兩位。
樣例輸入
1
-1 2
2
-8 6 9
0
樣例輸出
1.00
0.50
#include <bits/stdc++.h>
using namespace std
;
#define ll long long
int n
,cf
[15];
double l
,r
,mid
,ans
,t
,tt
,sum
;
int main()
{ios
::sync_with_stdio(false);while(cin
>>n
&&n
){for(int i
=0;i
<=n
;i
++)cin
>>cf
[i
];l
=-1.0;r
=1000000;for(int i
=0;i
<100;i
++){ans
=l
+(r
-l
)/2;t
=1.0;tt
=0;for(int j
=1;j
<=n
;j
++){t
/=(1+ans
);tt
+=t
*cf
[j
]; }if(tt
<(-cf
[0])) r
=ans
;else l
=ans
; }cout
<<fixed
<<setprecision(2)<<ans
<<endl
;}return 0;
}
總結(jié)
以上是生活随笔為你收集整理的内部收益率(二分)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。