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\n",ans);
}

Alice's birthday

时间: 2024-08-07 06:00:58

Alice's birthday的相关文章

codeforces_346A Alice and Bob(数学)

题目链接:http://codeforces.com/problemset/problem/346/A 参考链接:http://blog.csdn.net/loy_184548/article/details/50174615 感受到数学在博弈论中的强大. 考虑最后终止状态的序列-无法取出任意两个数他们的差值不存在这个序列中:那么这必定是个首项等于公差的等差序列 而这个序列是 d 2d 3d....,因此可以通过a[1] a[2] a[3] ...的最大公约数得到 然后计算有几个数没在数组中,判

Codeforces Round #201 (Div. 1) / 346A Alice and Bob

#include <cstdio> #include <algorithm> using namespace std; int gcd(int a,int b) { return b?gcd(b,a%b):a; } int n[100+10]; int main() { int t,maxn = 0; scanf("%d",&t); for(int i=0; i<t; i++) { scanf("%d",&n[i]);

Linux 下用户(andy)创建的文件可让特定用户(alice)修改

添加用户组ateam 在root用户下创建目录 /home/ateam-text 添加andy alice tom 用户 把andy alice用户添加到作为补充组的ateam组 将目录 /home/ateam-text 的所属组改为ateam 更改目录/home/ateam-text 的组权限 此时andy alice 用户在 目录/home/ateam-text 下都有读写执行权限 而tom用户无读写权限 但对于andy alice用户 分别在目录/home/ateam-text下创建的子目

HDU4268 Alice and Bob 【贪心】

Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2869    Accepted Submission(s): 926 Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this

博弈问题-Alice与Bob拿牌游戏

Description Bob and Alice play a game, and Bob will play first. Here is the rule of the game: 1) There are N stones at first; 2) Bob and Alice take turns to remove stones. Each time, they can remove p^k stones. p is prime number, such as 2, 3, 5, ...

Codeforces 346A Alice and Bob 博弈

http://codeforces.com/problemset/problem/346/A 题意:A和B两个人进行游戏,每人轮流操作,每次从集合(集合元素个数n<=100)取出两个数x,y将|x-y|放入集合中 (|x-y|不存在集合中)不能操作则输 最终游戏结束的标志是无法取出两个数字,他们的差值不在序列中.也就是说,最终状态是一个首项等于公差的等差序列.求出这个等差数列的项数-n,就是游戏进行的回合. 所以我们要先求出首项.设首项为d,接下来就是d+d,d+2d-.后面几项都是首项的倍数

Alice and Bob

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a se

hdu 4122 Alice&#39;s mooncake shop

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4122 题意大意是Alice开着一家月饼店,可以接到n做月饼的订单,而Alice只有在从2000年一月一日0点为第一个小时开始的前m个小时内做月饼,而且只能在整点 的时候做月饼,并且做月饼不花费时间,也就是一瞬间就可以做超级多的月饼,而每个月饼有t个小时的保质期,每个月饼保存每小时需要花费s元,而在可以 做月饼的m小时内,不同小时做月饼花费的钱也不同,每个订单都有交付订单嗯达时间,某年某月某日某时交付该

HDU 4122 Alice&#39;s mooncake shop 单调队列优化dp

Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4122 Description The Mid-Autumn Festival, also known as the Moon Festival or Zhongqiu Festival is a popular harvest festival celebrated by Ch

HDU 4111 Alice and Bob (博弈)

Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1799    Accepted Submission(s): 650 Problem Description Alice and Bob are very smart guys and they like to play all kinds of games i