第六届省赛 E Internal Rate of Return(UVA 11881)二分求根
2014-10-03 14:40
375 查看
题意:
+
+
... +
=
CF0
分析:这题有点坑,输出还说,如果不存在根输出NO,多个根输出“many Too many”通过限制条件分析,方程有且仅有一个实根,CF0>0,0<CFi<=10000 均为整数,而且结果精确到小数点后两位,看下图:
发现因为CF0为正整数,故CF0最小为1,可知IRR最大为10^4。
二分求方程根即可!
+
+
... +
=
CF0
分析:这题有点坑,输出还说,如果不存在根输出NO,多个根输出“many Too many”通过限制条件分析,方程有且仅有一个实根,CF0>0,0<CFi<=10000 均为整数,而且结果精确到小数点后两位,看下图:
发现因为CF0为正整数,故CF0最小为1,可知IRR最大为10^4。
二分求方程根即可!
int a[12]={0},n; double cal(double IRR) { double sum=a ; for(int i=n;i>0;i--) sum=sum/(1.0+IRR)+a[i-1]; return sum; } int main() { double cf0; while(~scanf("%d",&n)&&n) { scanf("%lf",&cf0); cf0=-cf0; for(int i=1;i<=n;i++)scanf("%d",a+i); double l=-1.0,r=10e4,mid; for(int i=0;i<40;i++) { mid=(l+r)/2.0; if(cal(mid)<cf0)r=mid; else l=mid; //if(r-l<eps)break; } printf("%.2f\n",mid); } return 0; }
相关文章推荐
- UVA 11881 Internal Rate of Return(数学+二分)
- UVA 11881(Internal Rate of Return)二分法
- Internal Rate Of Return - IRR
- toj 4609 Internal Rate of Return
- E - Internal Rate of Return
- UVA 113-Power of Cryptography(二分+double处理大数据)
- UVA - 113 Power of Cryptography (大数幂+二分)
- 15年湖南ACM省赛 Internet of Lights and Switches(异或运算+状压+二分)
- 2015山东省第六届ACM省赛 Nias and Tug-of-War
- Return of the Nim----Nim博弈+威佐夫博弈 山东省第八届省赛A题
- UVa 10341 (二分求根) Solve It
- 山东省第八届ACM省赛A.Return of the Nim
- 山东省第八届省赛 Return of the Nim(博弈)
- UVA-11149 Power of Matrix(矩阵二分幂)
- 山东省第八届省赛A题 Return of the Nim
- UVA 11149 Power of Matrix(矩阵+二分)
- 山东省第八届acm省赛 Return of the Nim
- UVA 1730 Sum of MSLCM 【数学】【二分】
- Guardian of Decency UVA - 12083 (二分匹配)
- UVA 113 - Power of Cryptography(二分)