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 ...
随机推荐
- js 判断是什么浏览器、是否为谷歌浏览器
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http ...
- python hdfs初体验
新建目录 chr 新建文件hdfstest1.txt并写入内容 复制hdfstest1.txt的内容到hdfstest2.txt
- 【转】数据库SQL的一些总结
http://www.cnblogs.com/yank/category/104903.html
- VC-基础:隐藏不安全函数的warning-_CRT_SECURE_NO_WARNINGS
>tmp.cpp(): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strc ...
- CeontOS6.5安装php环境
港湾云主机重装操作系统之后xshell无法连接:重启ssh:# service sshd restart -bash: vim: command not found:输入 rpm -qa|grep v ...
- 菜鸟学习Cocos2d-x 3.x——内存管理
菜鸟学习Cocos2d-x 3.x——内存管理 2014-12-10 分类:Cocos2d-x / 游戏开发 阅读(394) 评论(6) 亘古不变的东西 到现在,内存已经非常便宜,但是也不是可以 ...
- 【简●解】 LG P2730 【魔板 Magic Squares】
LG P2730 [魔板 Magic Squares] [题目背景] 在成功地发明了魔方之后,鲁比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 ...
- c++ 将输入存储到数组,然后反转数组,最后输出
// 输入一个包含多个double元素的数组,先打印结果,然后反转出头和尾元素之外的所有元素,最后再打印结果 #include <iostream> using namespace std ...
- css3的border-radius属性使用方法
1.border-radius可以包含两个参数值,第一个水平圆角半径,第二个为垂直半径,并且两个参数值用“/”分开. 2.border-radius:设置一个值为四个角都相同,两个值为左上和右下相同, ...
- XML,面向对象基础
什么是XML XML与JSON的对比 XML文档格式 使用XML模块解析 一,什么是XML ''' XML 全称可扩展标记语言 <tag></tag> 双标签 <tag/ ...