ACM-HDoj暑假竞赛(7)-1009解题报告(

新浪博客 发表时间 -- 2009-07-27 16:38:21)

题目:

Suppose you open a savings account with a certain initial balance. You will not make any withdrawals or further deposits for a number of years. The bank will compound your balance (add the annual interest) once a year, on the anniversary of the opening of the account. Your goal is to achieve a certain target amount in your savings account.

In how may years will the target amount be achieved?
Input:<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr> The input file will contain data for one or more test cases, one test case per line. Each line will contain three numbers: the initial balance, the annual interest rate (as a percentage of the balance), and the target amount, separated by blank spaces. These will be positive numbers; they may or may not contain a decimal point.<br> The target amount will be greater than the initial balance. The input is terminated by end-of-file</wbr></wbr></wbr></wbr>
Outp:
<wbr><wbr><wbr> For each line of input, your program will produce exactly one line of output: This line will contain one positive integer value: the number of years required to achieve the target amount.</wbr></wbr></wbr>
数据......
Sample Input:
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> 200.00 6.5 300<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> 500 4 1000.00</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
Sample Output:
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> 7</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> 18</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
算法:
<wbr><wbr><wbr><wbr><wbr> 虽然说英文不太懂,但一看到这个题目就大致猜到题意了,输入的数据是本金,利率,和最终所得的金额,求的是经过多少年能达到总金额,也就是第三个数.这应该是道很简单的初中数学题,幸好,还记得那个公式,一想到这就有点兴奋了,赶紧奋笔疾书...额,想想...P=(1+r%)^N*S...</wbr></wbr></wbr></wbr></wbr>
P为总金额,r为每年的利润率,S为本金..有这公式就好办了...
代码:
<wbr><wbr><wbr><wbr> #include "stdio.h"<br><wbr><wbr> #include "math.h"<br> int main()<br> {<br><wbr>int year;<br><wbr>float initial,rate,value,t,rate1;<br><wbr>while (scanf("%f %f %f",&amp;initial,&amp;rate,&amp;value)!=EOF)<br><wbr>{<br><wbr><wbr>year=0;<br><wbr><wbr>rate1=rate/100;<br><wbr><wbr>t=value/initial;<br><wbr><wbr>year=log10(t)/log10(1+rate1);<br><wbr><wbr>printf("%d\n",year+1);<br><wbr>}<br> }</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值