UVA 11881 Internal Rate of Return
来源:互联网 发布:smtp服务器端口25 编辑:程序博客网 时间:2024/06/03 15:59
f(x)=c0+c1*(1+x)^(-1)+c2*(1+x)^(-2)+...+cn*(1+x)^(-n)=0;
保证c0<0,10000>c1...cn>0,求x在(-1,inf)的解。
求导后发现导函数在定义域上恒小于0,而x趋近于0+时f(x)无穷大,所以在定义域上恒有唯一解,直接二分判断答案..
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;typedef long long ll;const double inf=1e7;const double eps=1e-6;int n,m;double a[22];int dcmp(double x){ if (fabs(x)<eps) return 0; else return x<0?-1:1;}double pw(double x,int c){ if (c==0) return 1.0; double res=1; for (int i=1; i<=c; i++) { res*=x; } if (dcmp(res)==0) return inf; return 1/res;}double f(double x){ double res=0; for (int i=0; i<n; i++) { res+=a[i]*pw(x,i); } return res;}int main(){// freopen("in.txt","r",stdin); while(cin>>n && n) { n++; for (int i=0; i<n; i++) cin>>a[i]; double l=0.000001,r=1000000.0; double mid; while(l<r) { mid=(l+r)/2.0; int k=dcmp(f(mid)); if (k==-1) r=mid; else if (k==1) l=mid; else if (k==0) { l=r=mid; break; } } printf("%.2lf\n",l-1.0); } return 0;}
0 0
- UVA 11881(Internal Rate of Return)二分法
- UVA 11881 Internal Rate of Return
- Internal Rate Of Return - IRR
- 第六届省赛 E Internal Rate of Return(UVA 11881)二分求根
- toj 4609 Internal Rate of Return
- 1017. Rate of Return
- 1017 Rate of Return
- 1017. Rate of Return
- sicily1017 Rate of Return
- sicily 1017. Rate of Return
- [sicily online]1017. Rate of Return
- 1017. Rate of Return (用二分法求近似解)
- POJ-2199(一元n次方程,二分答案)(Rate of Return )
- POJ-2199 Rate of Return【二分求解一元高次方程】
- UVa 759-The Return of the Roman Empire
- Principle of Rate Control Algorithm TMN5
- Success Rate of iBots in OBIEE
- Understanding different types of bit-rate encoding
- Android游戏开发入门讲解-SurfaceView-1
- Android开发:Eclipse导入Android项目 项目导入常见问题 中文乱码解决
- XML - Schema之引入其他Schema的方式
- HDU 3899 求所有人移动到某点的最小距离和 树形dp
- 微信开发者模式 绑定url token 您的服务器没有正确相应token验证
- UVA 11881 Internal Rate of Return
- 命令行参数wmain (int argc,wchar_t *argv[])
- 利用ViewHolder优化自定义Adapter的典型写法
- ttyS、ttySAC、tty、ttyn的区别
- Shell编程基础系列(2)------一些基本的命令
- struts2中如何去掉<s:fielderror>中的<ul><li>样式
- 基于C++标准库的动态绑定设计与实现
- OpenCV之cvSmooth函数平滑滤波
- ant打包build.xml配置