zoukankan      html  css  js  c++  java
  • Codeforces Round #393 (Div. 2) D题Travel Card(map,dp)解题报告

    A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.

    The fare is constructed in the following manner. There are three types of tickets:

    1. a ticket for one trip costs 20 byteland rubles,
    2. a ticket for 90 minutes costs 50 byteland rubles,
    3. a ticket for one day (1440 minutes) costs 120 byteland rubles.

    Note that a ticket for x minutes activated at time t can be used for trips started in time range from t to t + x - 1, inclusive. Assume that all trips take exactly one minute.

    To simplify the choice for the passenger, the system automatically chooses the optimal tickets. After each trip starts, the system analyses all the previous trips and the current trip and chooses a set of tickets for these trips with a minimum total cost. Let the minimum total cost of tickets to cover all trips from the first to the current is a, and the total sum charged before is b. Then the system charges the passenger the sum a - b.

    You have to write a program that, for given trips made by a passenger, calculates the sum the passenger is charged after each trip.

    Input

    The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger.

    Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1 ≤ i < n.

    Output

    Output n integers. For each trip, print the sum the passenger is charged after it.

    Example

    Input
    3
    10
    20
    30
    Output
    20
    20
    10
    Input
    10
    13
    45
    46
    60
    103
    115
    126
    150
    256
    516
    Output
    20
    20
    10
    0
    20
    0
    0
    20
    20
    10

    Note

    In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had already paid 40 rubles, so it is necessary to charge 10 rubles only.

    用map写的dp。建立花多少钱时的日期的记录,以此为dp对象。

    参考代码:

     1 #include<bits/stdc++.h>
     2 #include <iostream>
     3 #include <queue>
     4 #include <cstdio>
     5 #include <cstring>
     6 #include <algorithm>
     7 using namespace std;
     8 typedef long long ll;
     9 typedef unsigned long long ull;
    10 map<int,int> re;
    11 int n;
    12 int range=-1;
    13 int tem;
    14 int he=0;
    15 int oh;
    16 int an;
    17 int main()
    18 {
    19     scanf("%d",&n);
    20 //    re[0]=0;
    21     while(n--)
    22     {
    23         an=0;
    24         scanf("%d",&tem);
    25         if(tem<=range)
    26         {
    27             printf("0
    ");
    28             continue;
    29         }
    30         else
    31         {
    32             oh=he-40;
    33             if(oh>=0&&re.find(oh)!=re.end()&&re[oh]+89>=tem)
    34             {
    35                 range=max(range,re[oh]+89);
    36                 an=10;
    37             }
    38             oh=he-110;
    39             if(oh>=0&&re.find(oh)!=re.end()&&re[oh]+1439>=tem)
    40             {
    41                 range=max(range,re[oh]+1439);
    42                 an=10;
    43             }
    44             if(an!=0)
    45             {
    46                 re[he]=tem;
    47                 he+=10;
    48                 printf("%d
    ",an);
    49                 continue;
    50             }
    51             oh=he-30;
    52             if(oh>=0&&re.find(oh)!=re.end()&&re[oh]+89>=tem)
    53             {
    54                 range=max(range,re[oh]+89);
    55             }
    56             oh=he-100;
    57             if(oh>=0&&re.find(oh)!=re.end()&&re[oh]+1439>=tem)
    58             {
    59                 range=max(range,re[oh]+1439);
    60             }
    61             range=max(range,tem);
    62             printf("20
    ");
    63             re[he]=tem;
    64             he+=20;
    65         }
    66     }
    67 }
  • 相关阅读:
    awk 连接字符串
    VCF (Variant Call Format)格式详解
    Extracting info from VCF files
    JAVA中AES对称加密和解密
    关于Java中常用加密/解密方法的实现
    Java的MD5加密和解密
    java实现MD5加密
    Java中String和byte[]间的转换浅析
    Java中字符串和byte数组之间的相互转换
    字符串与byte[]之间的转换
  • 原文地址:https://www.cnblogs.com/quintessence/p/6392049.html
Copyright © 2011-2022 走看看