zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    JUnit常用断言及注解
    centos7 yum快速安装LNMP
    ceph问题汇总
    selinux介绍/状态查看/开启/关闭
    linux 修改主机名
    CentOS 7部署 Ceph分布式存储架构
    如何判断当前系统运行在物理机上还是虚拟机上,返回虚拟机的类型
    Golang操作结构体、Map转化为JSON
    PHP强制修改返回的状态码
    composer问题集锦
  • 原文地址:https://www.cnblogs.com/dyzll/p/6349985.html
Copyright © 2011-2022 走看看