Treasure Hunt II


Time Limit: 2 Seconds                                     Memory Limit: 65536 KB                            

There are n cities(1, 2, ... ,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 n, p 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<=100000, 1<=p<=n, 0<=vi<=100000, 0<=M<=100000, 0<=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


Author: LI, Chao                                                     Contest: ZOJ Monthly, July 2012

题意 转自:http://blog.csdn.net/cscj2010/article/details/7819110

题意:n个城市排成一行,每个城市中有vi个金币。两个人同时从同一个个城市出发,单位时间能走到相邻城市。

  • 到达城市获取金币不耗时间,且任意时刻两人距离不可以超过m,问t个时间他们最多能获得多少金币。
  • 如果 m >= t * 2,两个人两个方向一直走
  • 否则 两人一直向两边走指导相距m,注意,若m为奇数,则某人要停走一天。
  • 然后维持距离同时向左向右枚举剩余天数
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<vector> #define N 100005
#define M 15
#define mod 1000000007
#define mod2 100000000
#define ll long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n,p;
ll v[N];
ll tot;
ll sum[N];
int m,t;
int t1,t2; void ini()
{
int i;
tot=;
memset(sum,,sizeof(sum));
for(i=;i<=n;i++){
//scanf("%lld",&v[i]);
cin>>v[i];
sum[i]=sum[i-]+v[i];
}
scanf("%d%d",&m,&t);
} void solve()
{
int i,j,o;
if(m/>=t)
{
i=max(,p-t);
j=min(n,p+t);
tot=sum[j]-sum[i-];
return ;
}
t1=min(t,m/);
t2=t-t1;
i=max(,p-t);
j=min(n,p+t1);
tot=sum[j]-sum[i-];
for(o=;o<=t2;o++){
i=max(,p-t1-o);
if(m%== && o!=){
j=max(p+t1,p+t1+t2-*o+);
j=min(n,j);
} else{
j=max(p+t1,p+t1+t2-*o);
j=min(n,j);
}
tot=max(tot,sum[j]-sum[i-]);
} j=min(n,p+t);
i=max(,p-t1);
tot=max(tot,sum[j]-sum[i-]);
for(o=;o<=t2;o++){
if(m%== && o!=){
i=min(p-t1,p-t1-t2+*o-);
i=max(,i);
} else{
i=min(p-t1,p-t1-t2+*o);
i=max(,i);
} j=min(n,p+t1+o);
// printf(" o=%d i=%d j=%d sum=%I64d\n",o,i,j,sum[j]-sum[i-1]);
tot=max(tot,sum[j]-sum[i-]);
}
//tot=v[p];
// i=max(p-t,1);
//if(i==1){
// tot=sum[]
// }
// j=min(p+1,n); } int main()
{
//freopen("data.in","r",stdin);
// scanf("%d",&T);
// for(int cnt=1;cnt<=T;cnt++)
// while(T--)
while(scanf("%d%d",&n,&p)!=EOF)
{
//if(g==0 && b==0 &&s==0) break;
ini();
solve();
//printf("%lld\n",tot);
cout<<tot<<endl;
} return ;
}

zoj 3627#模拟#枚举的更多相关文章

  1. ZOJ 3627 Treasure Hunt II (贪心,模拟)

    题意:有n个城市并排着,每个城市有些珠宝,有两个人站在第s个城市准备收集珠宝,两人可以各自行动,但两人之间的距离不能超过dis,而且每经过一个城市就需要消耗1天,他们仅有t天时间收集珠宝,问最多能收集 ...

  2. PHP用Array模拟枚举

    C#中枚举Enum的写法: /// <summary> /// 公开类型 2-好友可见 1-公开 0-不公开 /// </summary> public enum OpenSt ...

  3. Luogu P1039 侦探推理(模拟+枚举)

    P1039 侦探推理 题意 题目描述 明明同学最近迷上了侦探漫画<柯南>并沉醉于推理游戏之中,于是他召集了一群同学玩推理游戏.游戏的内容是这样的,明明的同学们先商量好由其中的一个人充当罪犯 ...

  4. zoj 3627 Treasure Hunt II (贪心)

    本文出自   http://blog.csdn.net/shuangde800 题目链接:zoj-3627 题意 直线上有n个城市, 第i个城市和i+1个城市是相邻的.  每个城市都有vi的金币.   ...

  5. BZOJ 1088: [SCOI2005]扫雷Mine【思维题,神奇的模拟+枚举】

    1088: [SCOI2005]扫雷Mine Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3791  Solved: 2234[Submit][St ...

  6. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. USACO 1.3.4 Prime Cryptarithm 牛式(模拟枚举)

    Description 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ------- * * * * * * ------ ...

  8. Codeforces Round #417 (Div. 2)A B C E 模拟 枚举 二分 阶梯博弈

    A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. ACM-ICPC北京赛区(2017)网络赛1【模拟+枚举+数组操作】

    题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n ...

随机推荐

  1. WPF中退出时显示是否保存数据提示

    一.通过窗体中的按钮实现退出时数据保存提示 Xaml: <Grid> <TextBlock HorizontalAlignment="Left" Margin=& ...

  2. 第二次团队作业-PANTHER考勤系统需求分析

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 这个作业要求在哪里 https://edu.cnblo ...

  3. House of Spirit(fastbin)

    0x01 fastbin fastbin所包含chunk的大小为16 Bytes, 24 Bytes, 32 Bytes, … , 80 Bytes.当分配一块较小的内存(mem<=64 Byt ...

  4. vue-cli3.0 生产包去除console.log

    目前负责的公众号又迭代了一个版本,之前打生产包,配置总是和测试包搞混,所以使用了vue-cli3.0的环境变量来控制配置. 但是又发现了一个新问题,写代码的过程中写了很多console.log 来调试 ...

  5. 小型LAMP搭建

    一.dns的搭建 安装dns服务 yum install bind 修改dns的主配置文件 [root@234c17 named]# vim /etc/named.conf // // named.c ...

  6. $monitor用法

    1.$monitor 进程同一时间有且仅有一个,若多次调用$monitor,新进程会代替以前的monitor进程. 2.$fmonitor可以同时存在任意个. 3.一般不用$monitor系统函数. ...

  7. Python基础-__main__

    Python基础-_main_ 写在前面 如非特别说明,下文均基于Python3 一.__main__的官方解释 参考 _main_ -- Top-level script environment ' ...

  8. gnu printf可变参数宏

    可变参数的宏 标准C只支持可变参数的函数,意味着函数的参数可以是不固定的 例如printf()函数的原型是int printf(const char *format [,argument]...) 而 ...

  9. go 和make的用法 区别

    Doand Make are two verbs which frequently confuse students of English. Learn the Difference between ...

  10. tabel使用总结

    对日常使用到的tabel做下记录: <table cellspacing="0"><!--单元格间距为零 默认为2 border默认为 0--> <t ...