fzu 2244 Daxia want to buy house

来源:互联网 发布:plc和单片机有什么区别 编辑:程序博客网 时间:2024/06/09 19:31

http://acm.fzu.edu.cn/problem.php?pid=2244



很简单的水题,但是就是过不去,问题出在在C中,对于int型 *0.7和 *7/10是会出现精度上的问题。




#include<iostream>#include<cstdio>#include<cmath>using namespace std;const int inf=0x3f3f3f3f;int ma[1111][1111];int main(){    int all,gj;double nr,gr;int year;while(scanf("%d%d%lf%lf%d",&all,&gj,&nr,&gr,&year)!=EOF){ double yl1=nr/1200; double yl2=gr/1200;         int dk=all*7/10;         int sf=all-dk;         int sd;         if(dk<=gj)         sd=0,gj=dk;         else sd=dk-gj;         //每月还款额=贷款本金×[月利率×(1+月利率)^还款月数]÷[(1+月利率)^还款月数-1]         double ans;         ans=sd*1.0*(yl1*pow((1+yl1),year*12))/(pow((1+yl1),year*12)-1);         double ans1=gj*1.0*(yl2*pow((1+yl2),year*12))/(pow((1+yl2),year*12)-1);         long long int  ans11=(ans+ans1)*10000+0.5;         cout<<sf<<" "<<ans11<<endl;}return 0;}