zoukankan      html  css  js  c++  java
  • UESTC 1047 Alice's birthday

    原题地址:http://acm.uestc.edu.cn/#/problem/show/1047

    题意
    一条长为n的路,Bob要从一个端点走到另一个端点,途中有m个服务站,每个服务站提供两种服务可供选择
    1.瞬间向前前进一个单位的距离
    2.使Bob走过一个距离的要花的时间减1
    问Bob在每个服务站如何选择可以使自己最快到达路的另一端。

    题解
    对于方案二,永远是晚选不如早选
    所以贪心就好
    枚举选择方案二的次数

    决策问题:贪心 or DP

    #include<bits/stdc++.h>
    
    using namespace std;
    typedef long long LL;
    
    const int maxn=1e5;
    int dist[maxn+5];
    LL T[maxn+5];
    
    int main(void)
    {
        #ifdef ex
        freopen ("in.txt","r",stdin);
        //freopen ("out.txt","w",stdout);
        #endif
        
        LL n,m,t;
        
        scanf("%lld%lld%lld",&n,&m,&t);
        
        for (int i=1;i<=m;++i)
        {
            scanf("%d",&dist[i]);
        }
        
        T[0]=0;
        LL ans=t*(n-m);
        for (int i=1;i<=m;++i)
        {
            T[i]=T[i-1]+t*(dist[i]-dist[i-1]);
            ans=min(ans,T[i]+(t-1)*(n-dist[i]-(m-i)));
            --t;
            
            if (t==0) break;
        }
        
        printf("%lld
    ",ans);
    }
  • 相关阅读:
    Ajax技术
    java web中filter分析
    Async分析
    解释session
    XML相关知识
    开学第一课
    svn
    spa单页面应用(angular)
    angular
    webpack认识
  • 原文地址:https://www.cnblogs.com/123-123/p/5568361.html
Copyright © 2011-2022 走看看