• Travel Card


    Travel Card
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    Examples
    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 time20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs50 rubles, and the passenger had already paid 40 rubles, so it is necessary to charge 10 rubles only.

    分析:dp,考虑最后一次买票的情况有三种,二分得到这次买票的最优时间;

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <bitset>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    #define pii pair<int,int>
    #define sys system("pause")
    const int maxn=1e5+10;
    using namespace std;
    inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    inline void umax(ll &p,ll q){if(p<q)p=q;}
    inline void umin(ll &p,ll q){if(p>q)p=q;}
    inline ll read()
    {
        ll x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,m,k,t;
    ll dp[maxn],a[maxn];
    int main()
    {
        int i,j;
        scanf("%d",&n);
        rep(i,1,n)
        {
            a[i]=read();
            dp[i]=1e18;
            int pos;
            pos=lower_bound(a,a+i,a[i]+1-90)-a;
            if(pos)pos--;
            umin(dp[i],dp[pos]+50);
            pos=lower_bound(a,a+i,a[i]+1-1440)-a;
            if(pos)pos--;
            umin(dp[i],dp[pos]+120);
            umin(dp[i],dp[i-1]+20);
        }
        rep(i,1,n)printf("%lld
    ",dp[i]-dp[i-1]);
        return 0;
    }
  • 相关阅读:
    C++ 模板特化
    左值引用,右值引用以及移动语义
    搜狐2016研发工程师编程题
    java配置环境变量与常用技巧
    java在线聊天项目 使用SWT快速制作登录窗口,可视化窗口Design 更换窗口默认皮肤(切换Swing自带的几种皮肤如矩形带圆角)
    c++中的结构体:声明 定义 初始化
    用指针变量作函数形参接收数组地址,解决10个整数按由小到大顺序排序问题
    java在线聊天项目 实现基本聊天功能后补充的其他功能详细需求分析 及所需要掌握的Java知识基础 SWT的激活方法,swt开发包下载,及破解激活码
    java在线聊天项目1.0版 异常处理——开启多个客户端,关闭一个客户端后,在其他客户端中再发出信息会出现异常的处理
    第十一次作业
  • 原文地址:https://www.cnblogs.com/dyzll/p/6349985.html
Copyright © 2020-2023  润新知