暑假集训 #2 div1 I - Lada Priora 精度处理
2024-09-05 13:11:48
I - Lada Priora
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Winter in Yekaterinburg is the longest time of the year. And everyone spends long winter evenings in his own way. Max loves to drive through the city on his toned Lada Priora with lowered suspension. And nothing can stop him, neither snow nor ice. Well, except that a lamppost or a bus stop. Or, as today, the bumper of a black Mercedes with four strong guys inside that are not very happy with a bucket of bolts flown into their car. Now Max has a difficult choice. He can pay immediately for damage, not making the issue of an accident. Fortunately, Mercedes is the durable car, and all its damage is just a few scratches. Or Max can call the traffic police to register the accident as it should be. In this case, his insurance company will pay for the damage. In the second case the cost of insurance for Max in the next few years will be higher. Because Max calculates not so good, and the guys from Mercedes are already worried, he has called you to ask which of these two options is more advantageous for him.
This year, Max pays for the insurance c rubles. If he does not register the accident, then the next year he will pay c + d rubles, then c+ 2 d rubles, and so on, each following year the cost of insurance will rise d rubles. If he registers the accident, then for k years, starting from the next one, Max will have to pay for insurance p percent more. So the next year he will pay ( c + d) · (1 + p/100) rubles, then ( c + 2 d) · (1 + p/100) rubles, and so on.
Input
The first line contains an integer b that is the amount of money in rubles, which Max can pay the driver of the Mercedes, without registering the accident (1 ≤ b ≤ 10 5). The second line contains the integers c and d that are current insurance cost in rubles and how many rubles it increases every year if not to get into an accident (1 ≤ c, d ≤ 10 4). The third line contains integers k and p meaning how many years Max will have to buy more expensive insurance, and what percent its cost is higher than the cost of an usual insurance (1 ≤ k, p ≤ 100).
Output
If it is more advantageous for Max not to register the accident, then output in the first line “Cash”, otherwise output in the first line “Insurance” (including the case, if both options are equally disadvantageous). In the second line output the amount of money in rubles, that show how more advantageous your choice than the other one. The answer should be given with absolute or relative error not exceeding 10 −6.
Sample Input
input | output |
---|---|
10000 |
Cash |
15000 |
Insurance |
Notes
In the first example, the cost of insurance for the next three years is 21 000 rubles, if not to register the accident, and 31 500 rubles, if to register it.
In the second example, the cost of insurance for the next four years is 20 000 rubles, if not to register the accident, and 25 000 rubles, if to register it.
题意:一个人有两种付钱方式,第一种是先付一定数目的钱,然后第i年付c+i*d的钱
需要付费k年,另外一种是每年直接付费(c+i*d)(1+p/100)的钱,问选择哪种方式使得
付的钱最少。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int main()
{
long long b,c,d,k,p;
while(~scanf("%lld",&b))
{
scanf("%lld %lld",&c,&d);
scanf("%lld %lld",&k,&p);
long long tot=0;
for(int i=1;i<=k;i++) tot+=(c+i*d);
tot*=p;
if(tot>100*b) printf("Cash\n%.13f\n",tot/100.0-b);
else printf("Insurance\n%.13f\n",b-tot/100.0);
}
return 0;
}
分析:题目很简单,但是精度卡起来很变态,double被卡死了。只好采用大神们的
换成long long的写法,(因为double在进行if判断的时候可能会掉精度)long long处理精度时需要将相除改成相乘,但是long long 基本不会错
最新文章
- mac下使用sencha cmd+extjs6
- HTML5移动Web开发(七)——通过界面图标启动Web应用
- Codeforces 259 B - Little Pony and Sort by Shift
- ios - 文件保存路径的获取
- 【转】对 Xcode 菜单选项的详细探索(干货)
- Installation error INSTALL_FAILED_VERSION_DOWNGRADE错误
- java基础(十八)IO流(一)
- java基础知识再学习--maven
- 推荐5个漂亮的网站html源码
- System.Web.Caching.Cache 方法汇总
- HTML文档及标签介绍
- HTML友情链接代码
- Project Euler:Product-sum numbers (problem 88) C++
- 【iOS】Swift类的继承、构造方法、析构器等复习
- 技术文档分享_linux中生成考核用的GPT分区表结构修复
- 使用paginate分页后数据处理
- QT 窗口拖拽移动实现
- hdoj1004(查找众多字符串中个数最多的字符串)
- 各大APP注册时发送短信验证码是怎么实现的?
- x86 TargetPlatform with XBAPs