• zoj 3627 F


     
     
     
    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
    Submit Status

    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,"v1v2 ... 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
    

    Hint

    At day 1: Alice move to city 2, Bob move to city 4.

    They can always get the gold coins of the starting city, even if T=0

    贪心题。。一开始先尽量往两边走。。。走到最大距离M...

    如果M是奇数的话还要考虑最后一步是谁走(因为最后一步只能一个人走,两个人走就超过M了)

    然后分配剩下的时间。。如果往作走了i时间,那么往右就只能走t-2*i(因为还要回来)

    然后取所有状态的最大值就好了。。。。

    具体见代码注释。。。

      1 /*************************************************************************
      2     > File Name: code/zoj/3627.cpp
      3     > Author: 111qqz
      4     > Email: rkz2013@126.com 
      5     > Created Time: 2015年10月24日 星期六 17时00分25秒
      6  ************************************************************************/
      7 
      8 #include<iostream>
      9 #include<iomanip>
     10 #include<cstdio>
     11 #include<algorithm>
     12 #include<cmath>
     13 #include<cstring>
     14 #include<string>
     15 #include<map>
     16 #include<set>
     17 #include<queue>
     18 #include<vector>
     19 #include<stack>
     20 #include<cctype>
     21                  
     22 #define yn hez111qqz
     23 #define j1 cute111qqz
     24 #define ms(a,x) memset(a,x,sizeof(a))
     25 using namespace std;
     26 const int dx4[4]={1,0,0,-1};
     27 const int dy4[4]={0,-1,1,0};
     28 typedef long long LL;
     29 typedef double DB;
     30 const int inf = 0x3f3f3f3f;
     31 
     32 const int N=1E5+7;
     33 LL sum[N],v[N];
     34 
     35 int n,t,m,p;
     36 LL cal( int l,int r)
     37 {
     38     l = max(1,l);
     39     r = min(n,r);//边界处理
     40     return sum[r]-sum[l-1];
     41 }
     42 int main()
     43 {
     44   #ifndef  ONLINE_JUDGE 
     45    freopen("in.txt","r",stdin);
     46   #endif
     47 
     48    while (scanf("%d %d",&n,&p)!=EOF)
     49    {
     50        sum[0] = 0;
     51        for ( int i = 1 ; i <= n ; i++)
     52      {
     53      scanf("%lld",&v[i]);
     54      sum[i] = sum[i-1] + v[i];
     55      }
     56        
     57        scanf("%d %d",&m,&t);    
     58        int now = m ;
     59        int l,r;
     60        l=r=p;
     61        while (now>=2 &&t>0)  //在到达距离m之前(m为偶数)或m-1之前(m为奇数)时,同时往两边走
     62     {
     63         l--;
     64         r++;
     65         t--;
     66         now = now - 2;
     67 
     68     }
     69        LL ans = cal(l,r);   //在往两边走的过程中已经用完时间
     70        LL res;
     71        int mr,ml;
     72        for ( int i = 1 ; i <= t ; i++)  //先往右边走,分配时间
     73     {
     74         mr = r+i;
     75         int  tmp = r-m-(t-2*i); //往右走i时间,再回来还需要i时间
     76                     //此时还剩t-2*i时间,可以让之前再r-m位置的向左走到tmp位置
     77         ml = min(l,tmp);        //即使tmp比l大,tmp~l的部分再之前往两边走的过程中已经取过了,所以作端点至少为l
     78                     //换言之,要的是分配i时间走右边的时候能走的最长的那个区间
     79         res = cal(ml,mr);
     80         ans = max(ans,res);
     81        // cout<<"mr:"<<mr<<"tmp:"<<tmp<<" ml:"<<ml<<endl;
     82     }
     83 
     84        for ( int i = 1 ; i <= t ; i++) //先往左边走,分配时间,同理。
     85        {
     86        ml = l-i;
     87        int tmp = l+m+(t-2*i);
     88        mr =max(r,tmp);
     89        res = cal(ml,mr);
     90        ans = max(ans,res);
     91        }
     92        printf("%lld
    ",ans);
     93 }
     94   
     95    
     96  #ifndef ONLINE_JUDGE  
     97   fclose(stdin);
     98   #endif
     99     return 0;
    100 }
    View Code
  • 相关阅读:
    创建自定义图标和图像
    使用_CRTDBG_LEAK_CHECK_DF检查VC程序的内存泄漏(转)
    Hadoop Netflix数据统计分析2(转)
    系统提供的按钮和图标
    STATIC变量问题
    表格视图,文本视图和Web视图
    Hadoop Netflix数据统计分析1(转)
    获取程序数据路径(转)
    C++中STRING转为INT (转)
    netflix 推荐算法学习1(转)
  • 原文地址:https://www.cnblogs.com/111qqz/p/4914067.html
Copyright © 2020-2023  润新知