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;
}
目录
相关文章
|
11月前
|
算法
uva 10891 game of sum
题目链接 详细请参考刘汝佳《算法竞赛入门经典训练指南》 p67
23 0
UVa11506 - Angry Programmer(ISAP)
UVa11506 - Angry Programmer(ISAP)
51 0
Funny Car Racing - 最短路小技巧
题意: n个路口,m条街道,每条街道都是有向的 并且这m条街道open a秒 close b秒(循环往复),自己的车通过这条道路需要t秒 可以从路口等待某一条道路open,必须在道路close 之前通过,且必须在另一条道路open的时候进入 问能否从s点到达t点,如果不能,输出-1,如果能输出最短的时间 细节的地方加在了代码里,在建图的过程中,如果说a > t,那么说这条路无论如何是走不过去的,所以干脆直接不建边
84 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!".
924 0
ZOJ 1958. Friends
  题目链接:   ZOJ 1958. Friends   题目简介:     (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合。   (2)用运算符三种集合运算,'+' 表示两个集合的并集,'*' 表示两个集合的交集, '-' 表示从第一个集合中排除第二个集合包含的元素。
992 0
hdu 3172 Virtual Friends
点击打开3172 思路: 简单并查集 分析: 1 利用map对每个人进行编号,然后利用并查集即可 2 这一题有个地方就是输入case的时候要判断不等于EOF 代码: #include #include #include #incl...
642 0