首页 > ACM题库 > HDU-杭电 > hdu 2398 Savings Account-数学相关-[解题报告]C++
2014
01-05

hdu 2398 Savings Account-数学相关-[解题报告]C++

Savings Account

问题描述 :

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?

输入:

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. The target amount will be greater than the initial balance. The input is terminated by end-of-file

输出:

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. The target amount will be greater than the initial balance. The input is terminated by end-of-file

样例输入:

200.00 6.5 300
500 4 1000.00

样例输出:

7
18

/*
hdu	2398 Savings Account - 数学
*/
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	double x,y,a,l;
	int ret;
	while(cin>>x>>l>>y)
	{
		l=1+l/100;
		a=log(y/x)/log(l);//l^a=y/x
		ret=ceil(a);//向上取整  floor是向下
		cout<<ret<<endl;
	}
	return 0;
}

解题转自:http://blog.csdn.net/qq172108805/article/details/8777208


  1. 学算法中的数据结构学到一定程度会乐此不疲的,比如其中的2-3树,类似的红黑树,我甚至可以自己写个逻辑文件系统结构来。