zoukankan      html  css  js  c++  java
  • 【a702】贷款利率

    Time Limit: 10 second
    Memory Limit: 2 MB

    问题描述
    当一个人从银行贷款后,在一段时间内他将不得不每月尝还固定的分期付款。这个问题要求计算机出贷款者向银行支付的利率。假设利率按月累计。

    Input

    输入文件 仅一行包含三个用空格隔开的正整数。 第一个整数表示贷款的原值a,第二个整数表示每月支付的分期付款金额b,第三个整数表示分期付款还清贷款所需的总月数m。(1
    Output

    输出文件应该是一个实数,表示该贷款的月利率(用百分数表示),四舍五入精确到0.1%

    Sample Input

    1000 100 12
    Sample Output

    2.9

    【题目链接】:http://noi.qz5z.com/viewtask.asp?id=a702

    【题解】

    每个月需要在b当中扣除还没还完的钱(a)*月利率(x);
    然后再用被扣掉一部分的b去减a;
    重复上述过程;
    知道怎么算之后就二分利率是多少;
    然后看看利率为x的时候要还多少天f(x);
    如果f(x)<=c则可以让利率再高一点以让还多少天接近c;

    【完整代码】

    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <set>
    #include <map>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <stack>
    #include <string>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    void rel(LL &r)
    {
        r = 0;
        char t = getchar();
        while (!isdigit(t) && t!='-') t = getchar();
        LL sign = 1;
        if (t == '-')sign = -1;
        while (!isdigit(t)) t = getchar();
        while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
        r = r*sign;
    }
    
    void rei(int &r)
    {
        r = 0;
        char t = getchar();
        while (!isdigit(t)&&t!='-') t = getchar();
        int sign = 1;
        if (t == '-')sign = -1;
        while (!isdigit(t)) t = getchar();
        while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
        r = r*sign;
    }
    
    //const int MAXN = x;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    int a,b,c;
    
    int f(double x)
    {
        double ta = a;
        int month= 0;
        while (ta>0)
        {
            double temp = b;
            temp-=ta*x;
            if (temp<0)
                return 21e8;
            ta-=temp;
            month++;
        }
        return month;
    }
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        scanf("%d%d%d",&a,&b,&c);
        double l = 0.0,r = 1.0;
        double ans = 0.0;
        while (r-l>=0.0001)
        {
            double m = (l+r)/2.0;
            if (f(m)<=c)
                {
                    ans = m;
                    l = m;
                }
            else
                r = m;
        }
        ans*=100;
        printf("%.1lf
    ",ans);
        return 0;
    }
  • 相关阅读:
    拷贝构造函数的参数为什么必须使用引用类型(避免无限递归拷贝,但其实编译器已经强制要求了)
    MAKE gnu
    设计模式之观察者模式(Observable与Observer)
    WCF从零学习之设计和实现服务协定2
    CLR_Via_C#学习笔记之枚举
    事件与动画
    Shell—学习之心得
    Asp.net MVC中提交集合对象,实现Model绑定
    一个23岁大学生的开源项目 谷歌要竖中指了
    C++中的虚函数总结
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626861.html
Copyright © 2011-2022 走看看