• F


    Description

    There are n cities(12, ... ,n) forming a line on the wonderland. city i and city i+1 are adjacent and their distance is 1. Each city has many gold coins. Now, Alice and her friend Bob make a team to go treasure hunting. They starts at city p, and they want to get as many gold coins as possible in T days. Each day Alice and Bob can move to adjacent city or just stay at the place, and their action is independent. While as a team, their max distance can't exceed M.

    Input

    The input contains multiple cases.
    The first line of each case are two integers np as above.
    The following line contain n interger,"v1 v2 ... vn" indicate the gold coins in city i.
    The next line is M, T.
    (1<=n<=1000001<=p<=n0<=vi<=1000000<=M<=1000000<=T<=100000)

    Output

    Output the how many gold coins they can collect at most.

    Sample Input

    6 3
    1 2 3 3 5 4
    2 1
    
    

    Sample Output

    8
    ***********************************************************************************************************************************************************
    题意:两人在有限的距离内和时间内,走一定的格数,求走的格数权值之和最大
    ***********************************************************************************************************************************************************
     1 #include<iostream>
     2 #include<string>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<cstdio>
     6 #include<queue>
     7 #define LL long long
     8 using namespace std;
     9 LL sum[100001];
    10 LL val[100001],ans;
    11 int n,m,i,j,k,p,t;
    12 //该函数由右端决定前段,
    13 //两人向左向右走,然后走到相差m时,
    14 //再决定同时向左还是向右走,
    15 //比较求出最大值,这一过程需要枚举
    16 LL find(LL*sum,int p)
    17 {
    18     LL ans=val[p];
    19     int rt,et;
    20     for(rt=min(n,p+t);rt>=p;rt--)
    21     {
    22         int le=max(1,rt-m);
    23         le=max(le,p-t);
    24         int rest_t=t-max(p-le,rt-p);
    25         int l1=max(1,le-rest_t);
    26         int r1=min(n,rt+rest_t);
    27         ans=max(ans,max(sum[rt]-sum[l1-1],sum[r1]-sum[le-1]));
    28     }
    29     return ans;
    30 }
    31 int main()
    32 {
    33     while(scanf("%d %d",&n,&p)!=EOF)
    34     {
    35         sum[0]=0;
    36         ans=0;
    37         for(i=1;i<=n;i++)
    38         {
    39             scanf("%lld",&val[i]);
    40             sum[i]=sum[i-1]+val[i];
    41         }
    42         scanf("%d %d",&m,&t);
    43         LL ans=find(sum,p);
    44         for(i=1;i<=n/2;i++)//注意此处一定一定要转换,不然状态不全
    45          swap(val[i],val[n-i+1]);
    46         sum[0]=0;
    47         for(i=1;i<=n;i++)
    48          sum[i]=sum[i-1]+val[i];
    49         ans=max(ans,find(sum,n-p+1));
    50         printf("%lld
    ",ans);
    51     }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    Linux关闭防火墙命令
    js改变数组的两个元素的位子,互换、置顶
    vue nexttick的理解和使用场景
    vue mint-ui 框架下拉刷新上拉加载组件的使用
    vue项目中使用了vw适配方案,引入第三方ui框架mint-ui时,适配问题解决
    小程序开发笔记【二】,抽奖结果json数据拼装bug解决
    gulp插件gulp-nunjucks-render的使用及gulp4的简单了解
    小程序开发笔记【一】,查询用户参与活动列表 left join on的用法
    mysql数据插入前判断是否存在
    微信公众号通过图片选取接口上传到阿里oss
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3438751.html
Copyright © 2020-2023  润新知