zoj 3627#模拟#枚举

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为奇数,则某人要停走一天。
  • 然后维持距离同时向左向右枚举剩余天数
  1 #include<iostream>
  2 #include<cstring>
  3 #include<cstdlib>
  4 #include<cstdio>
  5 #include<algorithm>
  6 #include<cmath>
  7 #include<queue>
  8 #include<map>
  9 #include<vector>
 10
 11 #define N 100005
 12 #define M 15
 13 #define mod 1000000007
 14 #define mod2 100000000
 15 #define ll long long
 16 #define maxi(a,b) (a)>(b)? (a) : (b)
 17 #define mini(a,b) (a)<(b)? (a) : (b)
 18
 19 using namespace std;
 20
 21 int n,p;
 22 ll v[N];
 23 ll tot;
 24 ll sum[N];
 25 int m,t;
 26 int t1,t2;
 27
 28 void ini()
 29 {
 30    int i;
 31    tot=0;
 32    memset(sum,0,sizeof(sum));
 33    for(i=1;i<=n;i++){
 34         //scanf("%lld",&v[i]);
 35         cin>>v[i];
 36         sum[i]=sum[i-1]+v[i];
 37    }
 38    scanf("%d%d",&m,&t);
 39 }
 40
 41 void solve()
 42 {
 43     int i,j,o;
 44     if(m/2>=t)
 45     {
 46         i=max(1,p-t);
 47         j=min(n,p+t);
 48         tot=sum[j]-sum[i-1];
 49         return ;
 50     }
 51     t1=min(t,m/2);
 52     t2=t-t1;
 53     i=max(1,p-t);
 54     j=min(n,p+t1);
 55     tot=sum[j]-sum[i-1];
 56     for(o=0;o<=t2;o++){
 57         i=max(1,p-t1-o);
 58         if(m%2==1 && o!=0){
 59             j=max(p+t1,p+t1+t2-2*o+1);
 60             j=min(n,j);
 61         }
 62
 63         else{
 64             j=max(p+t1,p+t1+t2-2*o);
 65             j=min(n,j);
 66         }
 67         tot=max(tot,sum[j]-sum[i-1]);
 68     }
 69
 70     j=min(n,p+t);
 71     i=max(1,p-t1);
 72     tot=max(tot,sum[j]-sum[i-1]);
 73     for(o=0;o<=t2;o++){
 74         if(m%2==1 && o!=0){
 75             i=min(p-t1,p-t1-t2+2*o-1);
 76             i=max(1,i);
 77         }
 78
 79         else{
 80             i=min(p-t1,p-t1-t2+2*o);
 81             i=max(1,i);
 82         }
 83
 84         j=min(n,p+t1+o);
 85        // printf(" o=%d i=%d j=%d sum=%I64d\n",o,i,j,sum[j]-sum[i-1]);
 86         tot=max(tot,sum[j]-sum[i-1]);
 87     }
 88     //tot=v[p];
 89    // i=max(p-t,1);
 90     //if(i==1){
 91    //     tot=sum[]
 92    // }
 93    // j=min(p+1,n);
 94
 95 }
 96
 97 int main()
 98 {
 99     //freopen("data.in","r",stdin);
100    // scanf("%d",&T);
101    // for(int cnt=1;cnt<=T;cnt++)
102    // while(T--)
103     while(scanf("%d%d",&n,&p)!=EOF)
104     {
105         //if(g==0 && b==0 &&s==0) break;
106         ini();
107         solve();
108         //printf("%lld\n",tot);
109         cout<<tot<<endl;
110     }
111
112     return 0;
113 }
时间: 2024-11-08 19:01:47

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

zoj 3627(贪心)

思路:半夜了思路有点混乱wa了好几发.一开始坑定两个人距离为m才能获得最大的收益,所以我们就可以枚举单个端点,当距离达到m时在一同一个方向走这是我们只需要算一下剩下几秒,左右两边贪心去最大的即可. 代码如下: 1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟 枚举

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟  枚举 题意 一个红绿灯 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道让你判断,汽车是否有可能撞到行人 注意 当前车道的左转有可能撞到别的车道的行人的 题解 一大堆特判 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring&g

ZOJ 3674 模拟

[题意]:若干组数据 每组给一个整数n代表n个名词(单词),接下来1-n给出一个单词和一行注释(一行注释由多个字符串组成),然后给出一个整数m,接下来1-m 每行若干个单词来自(1-n),要求出这若干个单词共有的注释字符串并按字典序排列输出,若不存在则输出NO. Sample Input 4 fish agile animal horse swift animal eagle fierce animal Kyuubee alien incubator 2 fish horse eagle fis

枚举 用类的方法模拟枚举

package cn.itcast.day1; public class Weekday0 { private Weekday0(){} public static final Weekday0 SUN = new Weekday0(); public static final Weekday0 MON = new Weekday0(); public static final Weekday0 TUS = new Weekday0(); public static final Weekday0

JDK5新特性_2.模拟枚举类型

/** * 模拟枚举 * * @author Administrator * */ public abstract class T3_WeekDay { /** * 私有化构造器,防止用户创建对象 */ private T3_WeekDay() { } // 创建两个"枚举"对象 public static final T3_WeekDay SUN = new T3_WeekDay() { /** * 用匿名内部类去重写nextDay方法,将if,else,转移成了一个个独立的类 */

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

题意:有n个城市并排着,每个城市有些珠宝,有两个人站在第s个城市准备收集珠宝,两人可以各自行动,但两人之间的距离不能超过dis,而且每经过一个城市就需要消耗1天,他们仅有t天时间收集珠宝,问最多能收集多少珠宝? 思路: 其实就是类似一个滑动窗口在收集一个序列上的权值.首先两个人可以同时往两边散开,直到极限距离dis(这样省时),然后他们可能往左/右走,也可能往左走一会儿再往右走,也可能往右走一会儿再往左走.可以看出其实这些考虑都是对称的,那么我们主要考虑1边就行了.可以尝试枚举往左边走k天,其他

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

题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0, 1, 2, …, n-1. He plans to spend m consecutive days(2 ≤ m ≤ n)in Beijing. During

poj 1416 Shredding Company 模拟+枚举

题意: 给一个目标数和一个待分割数,可以对待分割数进行任意划分,比如将带分割数12305分为12,30,5,问将分好的数加起来最接近且不超过目标数的分割方案. 分析: 关键是在对带分割数的任意划分,直接for循环枚举状态,比如状态10101(二进制)表示将12305分为1,23,05. 代码: #include <iostream> #include <vector> using namespace std; int t,len; char a[12]; int vis[10000

ZOJ 3829 模拟贪心

2014牡丹江现场赛水题 给出波兰式,判断其是否合法,如果不合法有两种操作: 1:任意位置加一个数字或者操作符 2:任意两个位置的元素对调 贪心模拟即可 先判断数字数是否大于操作符数,若不大于 ans+=sum2-sum1+1:新加入的数字全部放到左端. 然后从左到右遍历一遍,存储到当前位置为止,数字数和sum1,和操作数和sum2 若sum2>=1sum1,优先与队尾的数字对调,若没有则sum1++,表示在最左端加一个数字 #include "stdio.h" #include