zoukankan      html  css  js  c++  java
  • 暑假集训 #2 div1 I

    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

    inputoutput
    10000
    5000 1000
    3 50
    
    Cash
    500.00
    
    15000
    2500 1000
    4 25
    
    Insurance
    10000.00
    

    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
    %.13f
    ",tot/100.0-b);
            else printf("Insurance
    %.13f
    ",b-tot/100.0);
        }
        return 0;
    }
    

    分析:题目很简单,但是精度卡起来很变态,double被卡死了。只好采用大神们的
    换成long long的写法,(因为double在进行if判断的时候可能会掉精度)long long处理精度时需要将相除改成相乘,但是long long 基本不会错

  • 相关阅读:
    数据源ObjectDataSource的数据访问类的编写
    ASP.NET网页文本编辑器的使用
    装饰模式
    策略模式
    代理模式
    备份、还原数据库
    简单工厂和工厂模式
    ASP.NET上传多个文件
    数据库访问类的编写
    UVA 11069 A Graph Problem
  • 原文地址:https://www.cnblogs.com/smilesundream/p/5664825.html
Copyright © 2011-2022 走看看