UVa 10114 loansome car Buyer (analog)

Source: Internet
Author: User
Tags time limit

10114-loansome Car Buyer

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1055

Kara Van and Lee Sabre are lonesome. A few months ago they took out a loan to buy a new car, but now they ' re stuck at home on Saturday night without wheels and Without money. You are there was a wreck and the car is totaled. Their insurance paid $10,000, the current value of the car. The only problem are that they owed the bank $15,000, and the bank wanted, payment, immediately since be no there a Car for collateral. In just a few moments, this unfortunate couple is not only lost the car, their but a lost additional in $5,000.

What Kara and Lee failed to account for is depreciation, the loss in value as the car ages. Each month the buyer ' s loan payment reduces the amount to the car. However, each month, the car also depreciates as it gets older. Your task is to write a program that calculates the "I", measured in months, that a car buyer owes the less money than A car is worth. For this problem, depreciation is specified as a percentage of the previous month ' s value.

Input consists of information for several loans. Each loan consists of one line containing the duration in months of the loan, the down payment, the amount of the loan, a d the number of depreciation records that follow. All values are are nonnegative, with the loans being at most-months long and car values at most $75,000. Since depreciation is not constant, the varying rates are-specified in a series of depreciation. Each depreciation record consists to one line with a month number and depreciation percentage, which are more than 0 and Le SS than 1. These are in strictly increasing the order by month, starting at month 0. Month 0 is the depreciation this applies immediately after driving the "car" the lot and is always present in the data. All the other percentages are the amount of depreciation in the end of the corresponding month. Not all months May is listed in the data. If a month is not listed, then the previous depreciation percentage. The end of the input is signalLed by a negative loan duration-the three values would be present but.

For simplicity, we'll assume a 0% interest loan, thus the car ' s initial value would be the loan amount plus the down Paym Ent. It is possible for a car ' s value and amount owed to be positive numbers less than. Do is round values to a whole number of cents ($7,347.635 should is rounded to $7,347.64).

Consider the example below of borrowing $15,000 for months. As the buyer drives off of the lot, he still owes $15,000, but the car has dropped into value by 10% to $13,950. After 4 months, the buyer has made 4 payments, each of $, and the car has further depreciated 3% in months 1 and 2 and 0.2% in months 3 and 4. At this time, the car was worth $13,073.10528 and the borrower only owes $13,000.

For each loan, the "is" is the number of complete months before borrower owes the ' car ' is less. Note that 中文版 requires plurals (5 months) on all values and other than one (1 month).

Example Input:

500.0 15000.0 3
0
1
3 002
500.0 9999.99 2
0 2/2400.0 30000.0 1 3. .2
1
025
-99 0 17000 1

Example output:

4 months
1 month
months

PS: The value of the No. 0 month car (loan amount + First payment) * (1-No. 0 Month depreciation rate)

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.