UVa 10114 Loansome Car Buyer (模拟)

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 see, there was a wreck and the car was totaled. Their insurance paid $10,000, the current value of the car. The only problem is that they owed the bank $15,000, and the bank wanted payment immediately, since there was no longer a car for collateral. In just a few moments, this unfortunate couple not only lost their car, but lost an additional $5,000 in cash too.

What Kara and Lee failed to account for was depreciation, the loss in value as the car ages. Each month the buyer's loan payment reduces the amount owed on the car. However, each month, the car also depreciates as it gets older. Your task is to write a program that calculates the first time, measured in months, that a car buyer owes 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, and the number of depreciation records that follow. All values are nonnegative, with loans being at most 100 months long and car values at most $75,000. Since depreciation is not constant, the varying rates are specified in a series of depreciation records. Each depreciation record consists of one line with a month number and depreciation percentage, which is more than 0 and less than 1. These are in strictly increasing order by month, starting at month 0. Month 0 is the depreciation that applies immediately after driving the car off the lot and is always present in the data. All the other percentages are the amount of depreciation at the end of the corresponding month. Not all months may be listed in the data. If a month is not listed, then the previous depreciation percentage applies. The end of the input is signalled by a negative loan duration - the other three values will be present but indeterminate.

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

Consider the first example below of borrowing $15,000 for 30 months. As the buyer drives off the lot, he still owes $15,000, but the car has dropped in value by 10% to $13,950. After 4 months, the buyer has made 4 payments, each of $500, 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 is worth $13,073.10528 and the borrower only owes $13,000.

For each loan, the output is the number of complete months before the borrower owes less than the car is worth. Note that English requires plurals (5 months) on all values other than one (1 month).

Example input:

30 500.0 15000.0 3
0 .10
1 .03
3 .002
12 500.0 9999.99 2
0 .05
2 .1
60 2400.0 30000.0 3
0 .2
1 .05
12 .025
-99 0 17000 1

Example output:

4 months
1 month
49 months

PS:第0个月车的价值为 (贷款额+首付款)*(1-第0个月的折旧率)

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索value
, and
, is
, of
, The
MONTH
carbuyer、carbuyer.co.uk、car buyer、carbuyer香蕉姐、carbuyer中文字幕,以便于您获取更多的相关知识。

时间: 2024-10-29 10:07:43

UVa 10114 Loansome Car Buyer (模拟)的相关文章

UVa 10205 Stack 'em Up (模拟)

10205 - Stack 'em Up Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1146 A standard playing card deck contains 52 cards, 13 values in each of four suits.

UVa 10194 Football (aka Soccer) (模拟)

10194 - Football (aka Soccer) Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=1135 The Problem Football the most popular sport in the world (americans ins

UVa 489 Hangman Judge:模拟&字符串匹配

489 - Hangman Judge Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=430 In ``Hangman Judge,'' you are to write a program that judges a series of Hangman g

算法题:UVa 591 Box of Bricks (模拟)

591 - Box of Bricks Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=53 2 Little Bob likes playing with his box of bricks. He puts the bricks one upon an

uva 540 Team Queue

点击打开链接uva 540 思路: list+map模拟 分析: 1 题目的意思是有n个队伍,每个队伍的人数为m. 2 现在有三种操作,ENQUEUE x是插入x,如果队列里面已经有x这一队的成员那么直接插入到这一队的最后一个,否则插入到队列的最后一个:DEQUEUE 是直接拿到队列的第一个元素输出,并删除队列的第一个元素:STOP是停止 3 直接利用map和list来模拟,由于题目要求要插入的具体的位置所以用list来模拟 代码: #include<map> #include<list

UVa 550 Multiplying by Rotation:模拟乘法

550 - Multiplying by Rotation Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=491 Warning: Not all numbers in this problem are decimal numbers! Multiplic

UVa 11210 Chinese Mahjong :模拟&amp;amp;枚举&amp;amp;回溯

11210 - Chinese Mahjong Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2151 Mahjong () is a game of Chinese origin usually played by four persons with tiles resembling dominoes and beari

UVa 131 The Psychic Poker Player:枚举&amp;amp;模拟好题

131 - The Psychic Poker Player Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=67 In 5-card draw poker, a player is dealt a hand of five cards (which may

UVa 133 The Dole Queue:模拟循环链表

133 - The Dole Queue Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=103&page=show_problem&problem=69 In a serious attempt to downsize (reduce) the dole queue, The New National Green