2888. 买房子

Mr.wu_

Please print “Impossible” directly.

speen123

include

define House_Price 270

define Max_Work_Years 30

int main()
{
int n = 0;
int k = 0;
int m = 0;
int i = 0;
while(scanf(“%d %d %d”,&n,&k,&m) != EOF){
double house_raise = k * 0.01;
double sallary_raise = m * 0.01;
double Now_House_Price = House_Price * 1.0;
double Now_Sallary = n * 1.0;
double Now_Saveing = n * 1.0;
for(i = 1;i < Max_Work_Years;i++){
if(Now_Saveing >= Now_House_Price){
break;
}
else{
Now_Sallary = Now_Sallary * (1.0 + sallary_raise);
Now_Saveing = Now_Saveing + Now_Sallary;
Now_House_Price = Now_House_Price * (1.0 + house_raise);
}
}
if(i > 29){
printf(“Impossible\n”);
}
else{
printf(“%d\n”,i);
}
}

return 0;

}

Li Dao

WA的话,可以参考下

include

using namespace std;
int n,k,m;
int solve()
{
double store=(double)n,price=double(270);
double salary=(double)n;
if(store-price>0) return 1;
for(int year=2;year<=30;year++)
{
salary=1+1.0m/100;
store+=salary;
price=1+1.0k/100;
if(store-price>0) return year;
}
return -1;
}
int main()
{
while(scanf(“%d%d%d”,&n,&k,&m)==3)
{
int ret=solve();
if(ret!=-1) cout<<ret<<endl;
else cout<<”Impossible”<<endl;
}
return 0;
}

你当前正在回复 博客/题目
存在问题!