UVa10114 - Loansome Car Buyer

简介: UVa10114 - Loansome Car Buyer
#include <iostream>#include <cstdio>usingnamespacestd;
constintN=8192;
doublem[N];
intmonth, number;
doublepayment, loan;
boolinput();
voidsolve();
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endifwhile (input()) {
solve();
    }
return0;
}
boolinput()
{
cin>>month>>payment>>loan>>number;
if (month<0) returnfalse;
intj=0;
for (inti=0; i<number; i++) {
intk;
doublex;
cin>>k>>x;
for (; j<k; j++) {
m[j] =m[j-1];
        }
m[j++] =x;
    }
for (; j<=month; j++) {
m[j] =m[j-1];
    }
returntrue;
}
voidsolve()
{
doubletotal=loan+payment;
doublep=loan/ (double)month;
total*= (1-m[0]);
inti;
for (i=0; i<month; i++) {
if (loan<total) break;
total*= (1-m[i+1]);
loan-=p;
    }
cout<<i<<" month"<< (i!=1?"s" : "") <<endl;
}
目录
相关文章
|
6月前
|
机器学习/深度学习 安全 Java
hdu-1596-find the safest road(dijkstra)
hdu-1596-find the safest road(dijkstra)
40 0
|
算法
uva 10891 game of sum
题目链接 详细请参考刘汝佳《算法竞赛入门经典训练指南》 p67
31 0
|
算法
light oj 1047 - Neighbor House 动态规划
动态规划,这个和刘汝佳算法竞赛入门经典P158的数字三角形有些相似,不过是求最小的值,而且有些限制,每次走到点和上次走的点不在同一列。
30 0
|
机器学习/深度学习 人工智能 BI
UPC Travel by Car (两次Floyd)
UPC Travel by Car (两次Floyd)
81 0
数论 - 组合数学 + 素数分解 --- hdu 2284 : Solve the puzzle, Save the world!
Solve the puzzle, Save the world! Problem Description In the popular TV series Heroes, there is a tagline "Save the cheerleader, Save the world!".
928 0