sicily1017 Rate of Return
来源:互联网 发布:淘宝网电脑版登录 编辑:程序博客网 时间:2024/06/06 10:02
题目链接:http://soj.sysu.edu.cn/1017
题目大意:给定一组数据,表示在第几个月存进多少钱,然后给出第 k (1<=k<=12)个月后钱的总数,要求根据这些条件算出出月利率(假设月利率是固定不变的)
解题思路:用二分法求解方程的近似根。由于题目只要求输出 5 位小数的值,对精度要求不高,故只需大概循环100次就能获得一个比较满意的近似根
#include <stdio.h>#include <math.h>int n, month[13];double money[13], start, end, middle;// 此函数用于二分法求解中判断函数值与 0 的大小double f(double m){double sum = 0.0;for (int i = 0; i < n; i++)sum += money[i] * pow(1 + m, month[n] - month[i] + 1);return sum - money[n];}int main(){int count = 1;while (1){scanf("%d", &n);if (n == -1)break;for (int i = 0; i <= n; i++)scanf("%d %lf", &month[i], &money[i]);start = 0.0;end = 1.0;// 二分法求解过程// 因为只要输出5位小数,所以其精度要求不是很高,循环100次就够了for (int i = 0; i < 100; i++){middle = (start + end) / 2;if (f(middle) < 0)start = middle;else if (f(middle) > 0)end = middle;elsebreak;}if (count > 1)printf("\n");printf("Case %d: %.5lf\n", count, middle);count++;}return 0;}
0 0
- sicily1017 Rate of Return
- 1017. Rate of Return
- 1017 Rate of Return
- 1017. Rate of Return
- Internal Rate Of Return - IRR
- sicily 1017. Rate of Return
- [sicily online]1017. Rate of Return
- UVA 11881(Internal Rate of Return)二分法
- UVA 11881 Internal Rate of Return
- toj 4609 Internal Rate of Return
- 1017. Rate of Return (用二分法求近似解)
- POJ-2199(一元n次方程,二分答案)(Rate of Return )
- 第六届省赛 E Internal Rate of Return(UVA 11881)二分求根
- POJ-2199 Rate of Return【二分求解一元高次方程】
- Principle of Rate Control Algorithm TMN5
- Success Rate of iBots in OBIEE
- Understanding different types of bit-rate encoding
- The Maximum Data Rate of a Channel
- QUST程序设计赛F题:Bash博弈
- ABAP Debugger Scripting的功能(非常强大)
- 1077. Kuchiguse (20)
- 算法第四版习题
- leetcode Unique Binary Search Trees II
- sicily1017 Rate of Return
- UVA 188
- NDK环境搭建
- Jetty嵌入式web的war的发布方法[张振华-Jack]
- 应用程序配置文件
- LDD3 short程序编译出错之修改
- Redis系列-配置文件小结
- mysql---源码安装
- OpenCV3.0学习(一)——OpenCV3.0 ALPHA在WIN8+VS2012环境下的配置