zoukankan      html  css  js  c++  java
  • Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks
    time limit per test:
    1 second
    memory limit per test:
    256 megabytes
    input:
    standard input
    output:
    standard output

    Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for arubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.

    What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.

    Input

    The only line contains 4 integers nabc (1 ≤ n, a, b, c ≤ 109).

    Output

    Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.

    Examples
    input
    1 1 3 4
    output
    3
    input
    6 2 1 1
    output
    1
    input
    4 4 4 4
    output
    0
    input
    999999999 1000000000 1000000000 1000000000
    output
    1000000000
    Note

    In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.

    In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total.

    In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.

    In the fourth example Alyona should buy one pack of one copybook.

    题目链接:http://codeforces.com/contest/740/problem/A


    题意:当前有n本书,需要买k本书,使得(n+k)是4的倍数。现在,买一本书需要a元,买2本书需要b元,买3本书需要k元。求最少需要花多少钱。

    思路:模拟。因为a,b,c其中有可能会有价格悬殊较大的情况,所以并不是买的越少越好。

    n%4  买书的钱

    1    3a,b+a,c;

    2    2a,b,2c;

    3    a,b+c,3c;

    这就是所有情况,输出最小的就可以了。

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 typedef __int64 ll;
     8 const int MAXN=1e5+100;
     9 const __int64 INF=1e9+100;
    10 int main()
    11 {
    12     __int64 n,a,b,c;
    13     scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
    14     b=min(2*a,b);
    15     c=min(min(3*a,a+b),c);
    16     n=n%4;
    17     if(n==0) cout<<0<<endl;
    18     else if(n==1)
    19         cout<<min(min(3*a,a+b),c);
    20     else if(n==2)
    21         cout<<min(min(2*a,b),2*c);
    22     else
    23         cout<<min(min(a,b+c),3*c);
    24     return 0;
    25 }
    View Code
    I am a slow walker,but I never walk backwards.
  • 相关阅读:
    音乐小转盘 css3 动画
    1.41
    1.4
    1.1
    课程设计——输出到TXT
    课程设计——c++中读取txt文件
    大二第一学期期末课程设计 2015.12.28
    无向图的广度优先遍历
    JS基本概念
    继承
  • 原文地址:https://www.cnblogs.com/GeekZRF/p/6099151.html
Copyright © 2011-2022 走看看