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为奇数,则某人要停走一天。
- 然后维持距离同时向左向右枚举剩余天数
#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#模拟#枚举的更多相关文章
- ZOJ 3627 Treasure Hunt II (贪心,模拟)
题意:有n个城市并排着,每个城市有些珠宝,有两个人站在第s个城市准备收集珠宝,两人可以各自行动,但两人之间的距离不能超过dis,而且每经过一个城市就需要消耗1天,他们仅有t天时间收集珠宝,问最多能收集 ...
- PHP用Array模拟枚举
C#中枚举Enum的写法: /// <summary> /// 公开类型 2-好友可见 1-公开 0-不公开 /// </summary> public enum OpenSt ...
- Luogu P1039 侦探推理(模拟+枚举)
P1039 侦探推理 题意 题目描述 明明同学最近迷上了侦探漫画<柯南>并沉醉于推理游戏之中,于是他召集了一群同学玩推理游戏.游戏的内容是这样的,明明的同学们先商量好由其中的一个人充当罪犯 ...
- zoj 3627 Treasure Hunt II (贪心)
本文出自 http://blog.csdn.net/shuangde800 题目链接:zoj-3627 题意 直线上有n个城市, 第i个城市和i+1个城市是相邻的. 每个城市都有vi的金币. ...
- BZOJ 1088: [SCOI2005]扫雷Mine【思维题,神奇的模拟+枚举】
1088: [SCOI2005]扫雷Mine Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3791 Solved: 2234[Submit][St ...
- UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- USACO 1.3.4 Prime Cryptarithm 牛式(模拟枚举)
Description 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ------- * * * * * * ------ ...
- 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 ...
- ACM-ICPC北京赛区(2017)网络赛1【模拟+枚举+数组操作】
题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n ...
随机推荐
- 关于bootstrap栅格系统的五等分以及八等分代码
众所周知,bootstrap的栅格系统是基于十二等分的,今天拿到设计的设计稿一看,发现一个图片list上只有8张图片,然后上网查资料,发现只能自己写css代码实现,故写博客记录代码. 以下是八等分的代 ...
- 如何在Mac OS X中开启或关闭显示隐藏文件命令
打开终端,输入:defaults write com.apple.finder AppleShowAllFiles -bool true 此命令显示隐藏文件defaults write com.app ...
- java面试基础篇(三)
1.Q:ArrayList 和 LinkedList 有什么区别? A:ArrayList查询快!LinkedList增删快.ArrayList是基于索引的数据接口,它的底层是数组.空间占用相对小一些 ...
- 浏览器window产生的缓存九种解决办法
浏览器缓存(Browser Caching)是浏览器端保存数据用于快速读取或避免重复资源请求的优化机制,有效的缓存使用可以避免重复的网络请求和浏览器快速地读取本地数据,整体上加速网页展示给用户.浏览器 ...
- WPF显示尺寸与设备无关问题
WPF单位 WPF窗口以及其中的所有元素都是用与设备无关的单位进行度量.一个与设备无关的单位被定义为1/96英寸.WPF程序统一用下面一个公式来定义物理单位尺寸: [ 物理单位尺寸(像素)] = [ ...
- 更新portage之后 安装 certbot
运行的时候一直报如下的错误: sudo certbot 错误结果: Traceback (most recent call last): File "/usr/lib/python-exec ...
- PyCharm 社区版创建Django项目的一个方法
PyCharm 社区版创建项目无法选择Django等项目,只能选择Python项目. 你在进行练习的时候为了方便,可以用过期了的PyCharm专业版在可用的30分钟内创建社区版本不支持的项目,再用Py ...
- java 比较String StringBuffer StringBuilder
String 字符串常量StringBuffer 字符串变量(线程安全)StringBuilder 字符串变量(非线程安全) 简要的说, String 类型和 StringBuffer 类型的主要性能 ...
- lombok安装、配置、使用
eclipse安装Lombok 运行安装: java -jar ${path}\lombok.jar 选择IDE所在路径点击Install/Update即可使用. 手动安装1. 将lombok.jar ...
- LDAP学习小结【仅原理和基础篇】
此篇文章花费了好几个晚上,大部分是软件翻译的英文文档,加上自己的理解所写,希望学习者能尊重每个人的努力. 我有句话想送给每个看我文章的人: 慢就是快,快就是慢!!! 另外更希望更多人能从认真从原理学习 ...