Page 1 of 3
10114 - Loansome Car Buyer
Posted: Wed Jul 16, 2003 11:30 pm
by Per
For the second test case, why isn't the answer "0 months."? (At this time the buyer owes 12*500 = 6000 dollars, but has a car worth 9974.99 dollars.)
For the third test case, how can the answer be 49? After 49 months, the buyer still owes (60-49)*2400 = 26400 dollars, almost as much as the car was worth from the beginning, and more than it was worth even after one month?
I'm guessing there is some subtle sentence in the problem statement that I'm missing, and I'd be thankful if someone could help me out.
Posted: Sat Aug 09, 2003 4:28 pm
by Whinii F.
It's a late reply but from the ranklist of the problem I see you not listed yet.
For the second test case, the total amount of loan is not 6000. $500 is the down payment, which were paid already, immediately after borrowing the money. The remaining loan to be paid is $9999.99 and it will be paid in 12 months. So your car's value is 9999.99 + 500 = 10499.99 and you owe 9999.99. The first depreciation in Month 0 causes the car to be 9974.9905 and that's still lesser than the loan.
But after the first month the car goes 9476.24 and you pay off 833.3325 so your remaining loan is 9166.66. So CAR > LOAN.
Hope I helped!

Posted: Sun Aug 10, 2003 3:46 pm
by Per
Ah, I had completely misunderstood the meaning of the downpayment!
Thanks a lot!
Re: 10114 - Loansome Car Buyer
Posted: Tue Jun 04, 2013 3:31 pm
by bonsu
Hi can anyone point me in the right direction, I'm not sure why i'm getting wrong answer? It passes on given test cases
Code: Select all
#include <fstream>
#include <map>
#include <iostream>
using namespace std;
int main()
{
// ifstream in("loan.in");
// ofstream out("loan.out");
int duration;
double deposit, amount, n_records;
int month;
while (cin >> duration >> deposit >> amount >> n_records) {
// cout << duration << " " << deposit << " " << amount << " " << n_records << endl;
if (duration < 0) break;
double repayment = amount / duration;
int mth, rcount = 0;
double rate, owed, car_worth = amount+deposit;
map<int, double> records;
for (int i = 0; i < n_records; ++i) {
cin >> mth >> rate;
// cout << mth << " " << rate << endl;
records[mth] = rate;
}
// cout << "r0: " << records[0] << endl;
mth = 0; rate = records[0];
//cout << duration << deposit << amount << n_records << endl;
for (int i = 0; i < duration; ++i) {
owed = amount-(repayment*(i));
if (owed < 0) break;
// cout << mth << endl;
if ((rcount < n_records)) {
// cout << "here" << endl;
// cout << i << endl;
// mth = i;
map<int,double>::iterator it = records.find(i);
if (it != records.end()) {
// cout << "here" << endl;
rate = it->second;
++rcount;
}
}
car_worth = car_worth - (car_worth*rate);
// cout << "month: " << i << " rate: " << rate << " car_worth: " << car_worth
// << " owed: " << owed << endl;
// cout << i << ": " << car_worth << endl;
if (owed < car_worth) {
month = i;
break;
}
// ++mth;
}
if (month > 1)
cout << month << " months" << endl;
else
cout << month << " month" << endl;
records.clear();
// cout << endl << endl;
}
return 0;
}
Re: 10114 - Loansome Car Buyer
Posted: Tue Jun 11, 2013 3:58 am
by brianfry713
Try input:
Code: Select all
100 0 75000 2
0 .10
99 .5
-1 0 0 0
AC output:
Re: 10114 - Loansome Car Buyer
Posted: Tue Jul 30, 2013 8:19 pm
by jiayeli
Whinii's post is helpful.
thank you
Re: 10114 - Loansome Car Buyer
Posted: Fri Aug 02, 2013 6:17 am
by fazel
hi guys
my code passed two testcases in problem and the one in here , but i'm still getting WA
Code: Select all
#include <iostream>
#include <vector>
#include <iterator>
using namespace std ;
int main ()
{
freopen("in.txt", "r",stdin);
int duration;
cin>>duration;
vector< double > deprice;
while (duration >0)
{
int numchangedeprice;
double owed , val ,loan , price ;
cin>>loan>>price>>numchangedeprice;
owed =price;
val = price+loan ;
int j,i, a[100];
double b[100];
cin>>a[0]>>b[0];
for ( i=1 ; i<numchangedeprice ; i++)
{
cin>>a[i]>>b[i];
deprice.insert(deprice.end(),a[i]-a[i-1],b[i-1]);
}
deprice.insert(deprice.end(), duration -a[i-1]+1,b[i-1]);
int t;
double pay = price / duration;
for (t =0; t <duration ; t++)
{
owed -=pay;
val = val*(1-deprice[t]);
//pay = owed / duration;
if ( owed< val)
break;
}
if (t==0)
cout <<"1 month"<<endl;
else
cout << t+1<<" months"<<endl;
deprice.clear();
cin>>duration;
}
}
Re: 10114 - Loansome Car Buyer
Posted: Sat Aug 03, 2013 1:17 am
by brianfry713
Don't read from a file. Try the I/O I posted above.
Re: 10114 - Loansome Car Buyer
Posted: Mon Sep 09, 2013 3:32 pm
by fazel
it passes the test that brainfry sent but still gives wrong answer
Code: Select all
#include <iostream>
#include <string>
#include <string.h>
#include <set>
#include <vector>
#include <stdio.h>
#include <map>
#include <stack>
#include <queue>
//#include <
#include <ctime>
#include <stdlib.h>
#include <search.h>
using namespace std ;
int main ()
{
//freopen("in.txt", "r",stdin);
//freopen("out.txt", "w", stdout);
int length, depricecnt;
double dpay,loan, a[110] , c[110];
int b[110];
cin>>length;
while (length >0)
{
cin>> dpay>> loan>> depricecnt;
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
memset(c, 0, sizeof c);
double value = dpay + loan , monthly = loan /length ;
for(int i =0 ; i<depricecnt;i++)
{
cin>>b[i];
cin>>a[i];
}
//fill c array
b[depricecnt] =length;
c[0] = a[0];
//int ii=0;
a[depricecnt]=a[depricecnt-1];
for(int i =1; i<=depricecnt; i++)
{
for(int t =b[i-1]; t <b[i]; t++)
c[t] = a[i-1];
}
c[length]=a[depricecnt-1];
/*for(int i=b[depricecnt-1]; i<length; i++)
c[i] =a[depricecnt-1];*/
value -= (c[0]*value);
int t =1;
for(t =1 ; t <length ; t++)
{
value -= (c[t]*value);
loan -= monthly;
if(loan <value)
break;
}
if (t ==1)
cout<<"1 month"<<endl;
else
cout<<t<<" months"<<endl;
cin>>length;
}
//cout<<double(CLOCKS_PER_SEC)/clock();
}
Re: 10114 - Loansome Car Buyer
Posted: Tue Sep 10, 2013 12:27 am
by brianfry713
Re: 10114 - Loansome Car Buyer
Posted: Tue Sep 10, 2013 10:36 pm
by fazel
thank u brain fry the problem was with that ,and one other that it should be exactly "0 months" not "0 month".
Re: 10114 - Loansome Car Buyer
Posted: Fri Oct 04, 2013 1:29 pm
by f.maru
Hi
my program answers are wrong but they are logical because i check them.
Code: Select all
#include<iostream>
using namespace std;
int main()
{
double month, down,loan,numd,d[200]={0};
while(cin>>month>>down>>loan>>numd)
{
int q;
for(int i=0;i<numd;i++)
{
cin>>q;
cin>>d[q];
}
double set;
for(int i=0;i<=month;i++)
{
if(d[i]==0)
d[i]=set;
else
set=d[i];
}
bool flag=true;
double owe=loan,worth=loan-(loan*d[0]);
int ans=0;
while(owe>worth)
{
ans++;
owe-=down;
worth=worth-(worth*d[ans]);
}
cout<<ans<<" months"<<endl;
}
}
and one more thing i think that if 15000 drop 10% we get 13500 not 13950 why in the problem example, it said 13950 ?????

Re: 10114 - Loansome Car Buyer
Posted: Tue Oct 08, 2013 3:10 am
by brianfry713
The cars initial value is the down payment $500 plus the loan amount $15,000 = $15,500. As the buy drives it off the lot it depreciates to $15,500 * (1.0 - 0.1) = $13,950
Re: 10114 - Loansome Car Buyer
Posted: Tue Oct 15, 2013 3:06 am
by lmky
I past the test case for 0 months, and all the test cases given in the problem statement, and I getting WA
Are there anymore critical test cases???
Re: 10114 - Loansome Car Buyer
Posted: Sat Dec 07, 2013 3:53 pm
by ccsnail
brianfry713 wrote:Try input:
Code: Select all
100 0 75000 2
0 .10
99 .5
-1 0 0 0
AC output:
hi, I didn't pass this test case. I want to know why, can you explain for me? thanks.
I think during month 1 to 98, the depreciation is zero. and month 99 and 100, depreciation is 0.5. Right ? Wrong? and My program result for this testcase is 11 months.