You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n; //n:表示贷款的原值
int m; //m:表示每月支付的分期付款金额
int K; //k:分期付款还清贷款所需的总月数
const double eps = 1e-8; // eps表示精度取决于题目对精度的要求
/**
首先看for()由题意得他是分k个月还完的所以当然要循环k次了
知道了月利率为 x
第 1个月他欠银行 n+n*x ,但由题意得,他每个月向银行还 m元钱所以下个月前还欠银行 n+n*x-m
第 2个月欠银行 (n+n*x-m)+(n+n*x-m)*x 还款m元
...
以此类推直到第k个月后求出他还欠银行的钱数
如果欠的钱数 > 0 ,说明在月利率为 x 的情况下每月还m元是无法还清的需要减小mid值
*/
bool check(double mid) {
double t = n; //贷款额
for (int i = 1; i <= k; ++i) {//k个月
t += t * mid; //贷款的利息在增加
t -= m; //货款的金额在减少
}
return t > 0; //还了足够的金额
}
int main() {
cin >> n >> m >> k;
double l = 0, r = 5;
while (r - l > eps) {
double mid = (l + r) / 2;
if (check(mid)) r = mid; // 如果还欠银行钱,说明利率太高,需要调低
else l = mid; //如果不欠银行钱,说明利率太低,需要调高
}
printf("%.1f", l * 100);//因为要显示百分比所以乘100
return 0;
}