zoukankan      html  css  js  c++  java
  • Atcoder 092

    A - Traveling Budget


    Time limit : 2sec / Memory limit : 256MB

    Score : 100 points

    Problem Statement

    You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and Dyen if you buy an unlimited ticket.

    Find the minimum total fare when the optimal choices are made for trains and buses.

    Constraints

    • 1≤A≤1 000
    • 1≤B≤1 000
    • 1≤C≤1 000
    • 1≤D≤1 000
    • All input values are integers.

    Input

    Input is given from Standard Input in the following format:

    A
    B
    C
    D
    

    Output

    Print the minimum total fare.


    Sample Input 1

    Copy
    600
    300
    220
    420
    

    Sample Output 1

    Copy
    520
    

    The train fare will be 600 yen if you buy ordinary tickets, and 300 yen if you buy an unlimited ticket. Thus, the optimal choice for trains is to buy an unlimited ticket for 300 yen. On the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen.

    Therefore, the minimum total fare is 300+220=520 yen.


    Sample Input 2

    Copy
    555
    555
    400
    200
    

    Sample Output 2

    Copy
    755
    

    Sample Input 3

    Copy
    549
    817
    715
    603
    

    Sample Output 3

    Copy
    1152
     1 #include <iostream>
     2 #include <vector>
     3 #include <algorithm>
     4 #include <string>
     5 #include <string.h>
     6 #include <cstring>
     7 #include <stdio.h>
     8 #define lowbit(x) x&(-x)
     9 
    10 using namespace std;
    11 const int maxn=105;
    12 typedef long long ll;
    13 
    14 
    15 int main(){
    16     ios::sync_with_stdio(0);
    17     ll a,b,c,d;
    18     cin>>a>>b>>c>>d;
    19     ll minn=min(a,b);
    20     ll minn2=min(c,d);
    21     cout<<minn+minn2<<endl;
    22    return 0;
    23 }

    B - Chocolate


    Time limit : 2sec / Memory limit : 256MB

    Score : 200 points

    Problem Statement

    Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1≤iN) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (Ai+1)-th day, the (2Ai+1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.

    Find the number of chocolate pieces prepared at the beginning of the camp.

    Constraints

    • 1≤N≤100
    • 1≤D≤100
    • 1≤X≤100
    • 1≤Ai≤100 (1≤iN)
    • All input values are integers.

    Input

    Input is given from Standard Input in the following format:

    N
    D X
    A1
    A2
    :
    AN
    

    Output

    Find the number of chocolate pieces prepared at the beginning of the camp.


    Sample Input 1

    Copy
    3
    7 1
    2
    5
    10
    

    Sample Output 1

    Copy
    8
    

    The camp has 3 participants and lasts for 7 days. Each participant eats chocolate pieces as follows:

    • The first participant eats one chocolate piece on Day 135 and 7, for a total of four.
    • The second participant eats one chocolate piece on Day 1 and 6, for a total of two.
    • The third participant eats one chocolate piece only on Day 1, for a total of one.

    Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1+4+2+1=8.


    Sample Input 2

    Copy
    2
    8 20
    1
    10
    

    Sample Output 2

    Copy
    29
    

    Sample Input 3

    Copy
    5
    30 44
    26
    18
    81
    18
    6
    

    Sample Output 3

    Copy
    56
     1 #include <iostream>
     2 #include <vector>
     3 #include <algorithm>
     4 #include <string>
     5 #include <string.h>
     6 #include <cstring>
     7 #include <stdio.h>
     8 #define lowbit(x) x&(-x)
     9 
    10 using namespace std;
    11 const int maxn=110;
    12 typedef long long ll;
    13 int a[maxn];
    14 
    15 int main(){
    16     ios::sync_with_stdio(0);
    17     int n,d,x;
    18     cin>>n>>d>>x;
    19     ll  m=0;
    20     memset(a,0,sizeof(a));
    21     for(int i=0;i<n;i++){
    22         cin>>a[i];
    23     }
    24     int tmp=0;
    25     for(int i=0;i<n;i++){
    26         tmp=a[i];
    27         if(tmp<d) {
    28             tmp+=1;
    29             m+=2;
    30         }
    31         else {
    32                 ++m;
    33                 continue;
    34             }
    35         while(tmp<d){
    36              tmp+=a[i];
    37              if(tmp<=d)
    38                ++m;
    39              else break;
    40         }
    41     }
    42     cout<<m+x<<endl;
    43    return 0;
    44 }
  • 相关阅读:
    TBDR下msaa 在metal vulkan和ogles的解决方案
    Load store action in vulkan & ogles 的解决方案
    百度 我日你全家
    metal sample code
    NativeRenderingPlugin IOS
    ranch实现游戏服务器
    erlang游戏开发tcp
    Erlang 命令行监控工具
    rebar安装及创建项目
    erlang中如何调试程序
  • 原文地址:https://www.cnblogs.com/z-712/p/8659294.html
Copyright © 2011-2022 走看看