toj 4609 Internal Rate of Return
来源:互联网 发布:配眼镜需要的数据 编辑:程序博客网 时间:2024/06/06 11:05
toj 4609 Internal Rate of Return
时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte
总提交: 17 测试通过:11
描述
In finance, Internal Rate of Return (IRR) is the discount rate of an investment when NPV equals zero. Formally, given T, CF0, CF1, …, CFT, then IRR is the solution to the following equation:
Your task is to find all valid IRRs. In this problem, the initial cash-flow CF0 < 0, while other cash-flows are all positive (CFi > 0 for all i = 1, 2,…).
Important: IRR can be negative, but it must be satisfied that IRR > - 1.
输入
There will be at most 25 test cases. Each test case contains two lines. The first line contains a single integer T ( 1≤T≤10), the number of positive cash-flows. The second line contains T + 1 integers: CF0, CF1, CF2, …, CFT, where CF0 < 0, 0 < CFi < 10000 ( i = 1, 2,…, T). The input terminates by T = 0.
输出
For each test case, print a single line, containing the value of IRR, rounded to two decimal points. If no IRR exists, print “No” (without quotes); if there are multiple IRRs, print “Too many”(without quotes).
样例输入
1
-1 2
2
-8 6 9
0
样例输出
1.00
0.50
#include <iostream>#include <cmath>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;#define eps 1e-5int main(){ int T, s[10000]; while(scanf("%d", &T) && T) { memset(s, 0, sizeof(s)); for(int i = 0; i <= T; i++) { scanf("%d", &s[i]); } //printf("%d\n", s[0]); double Q = 0; double left = -1; double right = 10000; int flag = 1; double mid = 0; while(1) { mid = (left + right) / 2; //cout << mid << endl; Q = s[0]; for(int i = 1; i <= T; i++) { if((1+mid) == 0) { flag = 0; break; } Q += s[i]/pow(1+mid, i*1.0); //cout << Q << endl; } if(flag == 0) { flag == 1; continue; } if(Q > eps) left = mid; else if(Q < -eps) right = mid; if(Q <= eps && Q >= -eps) break; } printf("%.2lf\n", mid); } return 0;}
- toj 4609 Internal Rate of Return
- Internal Rate Of Return - IRR
- UVA 11881(Internal Rate of Return)二分法
- UVA 11881 Internal Rate of Return
- 1017. Rate of Return
- 1017 Rate of Return
- 1017. Rate of Return
- sicily1017 Rate of Return
- 第六届省赛 E Internal Rate of Return(UVA 11881)二分求根
- 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【二分求解一元高次方程】
- TOJ Area of Circles
- TOJ : 1414. Temple of Dune
- TOJ 1601. Box of Bricks
- toj 4607 Multiple of 17
- 前端模块化开发的价值
- SNAT、DNAT、MASQUERADE的区别
- EventBus阅读源码(2)-SubscriberMethod
- UVa 1330 LA 3029
- HDU 1730 Northcott Game(Nim博弈变形)
- toj 4609 Internal Rate of Return
- 提取assets.car中的图片 .car文件的解压
- 【安卓开发】JAVA代码设置selector不同状态下的背景颜色
- navicat for mysql注册码,各种版本都有
- poj1745 Divisibility(动态规划经典题)
- 一步步学会使用SeaJS 2.0
- Pku oj 2104(划分树)
- hdu5213 莫队算法
- [Paper Reading] DeepLab v1 & v2